File tree 4 files changed +38
-12
lines changed
4 files changed +38
-12
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,9 @@ <h1>Character Search</h1>
22
22
< tbody >
23
23
< tr *ngFor ="let char of characters ">
24
24
< td colspan ="2 "> {{ char.characterName }}</ td >
25
- < td > {{ char.booksAsString() }}</ td >
25
+ < td >
26
+ < span [innerHTML] ="char.booksWithLineBreaksAndAnchors() "> </ span >
27
+ </ td >
26
28
</ tr >
27
29
</ tbody >
28
30
</ table >
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ export class CharacterComponent {
39
39
if ( resultJson . success ) {
40
40
this . characters = [ ] ;
41
41
result . json ( ) . result . forEach ( ( character :ApiCharacter ) => {
42
- this . characters . push ( new Character ( character . characterName , character . books ) ) ;
42
+ this . characters . push ( new Character ( character . characterName , character . books ) ) ;
43
43
} ) ;
44
44
}
45
45
@@ -53,5 +53,5 @@ export class CharacterComponent {
53
53
54
54
interface ApiCharacter {
55
55
characterName : string ;
56
- books : string [ ] ;
56
+ books : { [ key : number ] : string } ;
57
57
}
Original file line number Diff line number Diff line change @@ -66,7 +66,7 @@ export class Book extends BookBaseViewModel {
66
66
for ( let index = 0 ; index < this . series . length ; index ++ ) {
67
67
let seriesRecord = this . series [ index ] ;
68
68
returnString +=
69
- `<a href='/seriesProfile/${ seriesRecord . seriesId } '>${ seriesRecord . seriesName } </a>` ;
69
+ `<a href='/seriesProfile/${ seriesRecord . seriesId } '>${ seriesRecord . seriesName } </a></br> ` ;
70
70
}
71
71
return returnString ;
72
72
} ;
Original file line number Diff line number Diff line change 1
1
export class Character {
2
- constructor ( characterName : string , books : string [ ] ) {
2
+ constructor ( characterName : string , books : { [ key : number ] : string } ) {
3
3
this . characterName = characterName ;
4
- this . books = books ;
4
+
5
+ if ( books ) {
6
+ this . books = [ ] ;
7
+ for ( let key in books ) {
8
+ let value = books [ key ] ;
9
+ this . books . push ( new BookIdNameViewModel ( key , value ) ) ;
10
+ }
11
+ }
5
12
6
13
this . registerFunctions ( ) ;
7
14
}
8
15
characterName : string ;
9
- books : string [ ] ;
10
- booksAsString : ( ) => string ;
16
+ books : BookIdNameViewModel [ ] ;
17
+ booksWithLineBreaksAndAnchors : ( ) => string ;
11
18
12
19
registerFunctions = ( ) => {
13
- this . booksAsString = ( ) : string => {
14
- return this . books . length > 0
15
- ? this . books . join ( ',' )
16
- : '' ;
20
+ this . booksWithLineBreaksAndAnchors = ( ) : string => {
21
+ if ( this . books . length == 0 ) {
22
+ return '' ;
23
+ }
24
+
25
+ let returnString = '' ;
26
+ for ( let index = 0 ; index < this . books . length ; index ++ ) {
27
+ let bookRecord = this . books [ index ] ;
28
+ returnString +=
29
+ `<a href='/bookProfile/${ bookRecord . bookId } '>${ bookRecord . bookName } </a></br>` ;
30
+ }
31
+ return returnString ;
17
32
}
18
33
}
34
+ }
35
+
36
+ export class BookIdNameViewModel {
37
+ constructor ( bookId : string , bookName : string ) {
38
+ this . bookId = bookId ;
39
+ this . bookName = bookName ;
40
+ }
41
+ bookId : string ;
42
+ bookName : string ;
19
43
}
You can’t perform that action at this time.
0 commit comments