File tree Expand file tree Collapse file tree 4 files changed +36
-33
lines changed Expand file tree Collapse file tree 4 files changed +36
-33
lines changed Original file line number Diff line number Diff line change 13
13
} ,
14
14
_create : function ( ) {
15
15
$ . ui . datasource . types [ this . options . type ] = this ;
16
+ // TODO initialzing items[type] should probably be moved into the populate call
16
17
$ . ui . datastore . main . items [ this . options . type ] = [ ] ;
17
- // populate store with static data directly
18
- if ( $ . isArray ( this . options . source ) ) {
19
- // TODO pass this (as the datasource instance) instead of type?
20
- $ . ui . datastore . main . populate ( this . options . type ) ;
21
- }
18
+ $ . ui . datastore . main . populate ( this . options . type ) ;
22
19
} ,
23
20
create : function ( props ) {
24
21
this . options . source . push ( props ) ;
25
22
} ,
26
23
get : function ( store ) {
27
- store . _populate ( this . options . type , this . options . source ) ;
24
+ if ( $ . isArray ( this . options . source ) ) {
25
+ // TODO pass this (as the datasource instance) instead of type?
26
+ store . _populate ( this . options . type , this . options . source ) ;
27
+ } else if ( $ . isFunction ( this . options . source ) ) {
28
+ var that = this ;
29
+ this . options . source ( { } , function ( data ) {
30
+ store . _populate ( that . options . type , data ) ;
31
+ // TODO replace this workaround with proper notifications or async handling
32
+ $ ( "table" ) . grid ( "refresh" ) ;
33
+ } ) ;
34
+ }
35
+ // TODO typeof source == "string" => $.getJSON(source)?
28
36
} ,
29
37
save : function ( items ) {
30
38
$ . each ( items , function ( itemId , item ) {
Original file line number Diff line number Diff line change 51
51
} ,
52
52
// TODO or rename this
53
53
_populate : function ( type , items ) {
54
- // TODO just assign items to this.items[type]?
54
+ // remove cached dataitems object
55
+ delete this . dataitems [ type ] ;
55
56
var local = this . items [ type ] ;
56
57
$ . each ( items , function ( i , item ) {
57
- // TODO changed this to use index for proper array indexing
58
- // was item.guid which is not useful as array index
59
58
local [ i ] = item ;
60
59
} ) ;
61
60
} ,
Original file line number Diff line number Diff line change 1
1
[
2
2
{
3
- guid: 1,
4
- firstName: "Scott",
5
- lastName: "González",
6
- country: "USA",
7
- twitter: "scott_gonzalez",
8
- github: "scottgonzalez"
3
+ " guid" : 1 ,
4
+ " firstName" : " Scott" ,
5
+ " lastName" : " González" ,
6
+ " country" : " USA" ,
7
+ " twitter" : " scott_gonzalez" ,
8
+ " github" : " scottgonzalez"
9
9
},
10
10
{
11
- guid: 2,
12
- firstName: "Richard",
13
- lastName: "Worth",
14
- country: "USA",
15
- twitter: "rworth",
16
- github: "rdworth"
11
+ " guid" : 2 ,
12
+ " firstName" : " Richard" ,
13
+ " lastName" : " Worth" ,
14
+ " country" : " USA" ,
15
+ " twitter" : " rworth" ,
16
+ " github" : " rdworth"
17
17
},
18
18
{
19
- guid: 3,
20
- firstName: "Jörn",
21
- lastName: "Zaefferer",
22
- country: "Germany",
23
- twitter: "bassistance",
24
- github: "jzaefferer"
19
+ " guid" : 3 ,
20
+ " firstName" : " Jörn" ,
21
+ " lastName" : " Zaefferer" ,
22
+ " country" : " Germany" ,
23
+ " twitter" : " bassistance" ,
24
+ " github" : " jzaefferer"
25
25
}
26
26
]
Original file line number Diff line number Diff line change 8
8
< link rel ="stylesheet " href ="grid.css " />
9
9
< script src ="../../../jquery-1.4.4.js "> </ script >
10
10
< script src ="../../../external/jquery.tmpl.js "> </ script >
11
- < script src ="../../../external/jquery.global.js "> </ script >
12
- < script src ="../../../external/jquery.global.de-DE.js "> </ script >
13
- < script src ="../../../external/jquery.global.ja-JP.js "> </ script >
14
11
< script src ="../../../ui/jquery.ui.core.js "> </ script >
15
12
< script src ="../../../ui/jquery.ui.widget.js "> </ script >
16
13
< script src ="dataitem.js "> </ script >
24
21
$ . ui . datasource ( {
25
22
type : "developer" ,
26
23
source : function ( request , response ) {
27
- console . log ( this , arguments ) ;
28
- $ . getJSON ( "fixture.json" , response ) ;
24
+ $ . getJSON ( "fixture.json" , request , response ) ;
29
25
}
30
26
} ) ;
31
27
32
28
$ ( "table" ) . grid ( {
33
- type : "developers " ,
29
+ type : "developer " ,
34
30
// TODO remove this; move template generation from extractor to grid init or refresh
35
31
rowTemplate : $ ( "#row-tmpl" ) . html ( ) ,
36
32
} )
You can’t perform that action at this time.
0 commit comments