ExtJS:store.load()不加载数据

时间:2013-08-16 07:46:44

标签: javascript ajax extjs extjs4.2

我在ExtJS 4.2中遇到问题,即store.load()方法不从服务器加载数据,只检索json。 我的 js / itfx / resources / genres.json 文件:

[{"name":"Action & Adventure","code":"ACTION-ADVENTURE-00"},{"name":"African","code":"AFRICAN-00"},{"name":"Anime","code":"ANIME-00"},{"name":"Bollywood","code":"BOLLYWOOD-00"},{"name":"Classics","code":"CLASSICS-00"},{"name":"Comedy","code":"COMEDY-00"},{"name":"Concert Films","code":"CONCERT-FILMS-00"},{"name":"Documentary","code":"DOCUMENTARY-00"},{"name":"Drama","code":"DRAMA-00"},{"name":"Foreign","code":"FOREIGN-00"},{"name":"Holiday","code":"HOLIDAY-00"},{"name":"Horror","code":"HORROR-00"},{"name":"Independent","code":"INDEPENDENT-00"},{"name":"Kids & Family","code":"KIDS-FAMILY-00"},{"name":"Made for TV","code":"MADE-FOR-TV-00"},{"name":"Middle Eastern","code":"MIDDLE-EASTERN-00"},{"name":"Music Documentaries","code":"MUSIC-DOCUMENTARIES-00"},{"name":"Music Feature Film","code":"MUSIC-FEATURE-FILMS-00"},{"name":"Musicals","code":"MUSICALS-00"},{"name":"Regional Indian","code":"REGIONAL-INDIAN-00"},{"name":"Romance","code":"ROMANCE-00"},{"name":"Russian","code":"RUSSIAN-00"},{"name":"Sci-Fi & Fantasy","code":"SCIFI-FANTASY-00"},{"name":"Short Films","code":"SHORT-FILMS-00"},{"name":"Special Interest","code":"SPECIAL-INTEREST-00"},{"name":"Sports","code":"SPORTS-00"},{"name":"Thriller","code":"THRILLER-00"},{"name":"Turkish","code":"TURKISH-00"},{"name":"Urban","code":"URBAN-00"},{"name":"Western","code":"WESTERN-00"}]

我的模特:

Ext.define('ITFX.model.films.info.FilmGenre', {
    extend: 'Ext.data.Model',
    fields: [
        {name: 'name', type: 'string'},
        {name: 'code', type: 'string'}
    ]
});

我的商店:

Ext.define('ITFX.store.films.info.FilmGenre', {
    extend: 'Ext.data.Store',

    model: 'ITFX.model.films.info.FilmGenre',

    proxy: {
        type: 'ajax',
        url : 'js/itfx/resources/genres.json',
        reader: {
            type: 'json'
        }
    }
});

所以,在执行代码abowe之后:

var allFilmGenresStore = Ext.create('ITFX.store.films.info.FilmGenre');
allFilmGenresStore.load();

方法

allFilmGenresStore.getCount(); //0
allFilmGenresStore.getTotalCount(); //0

将返回,该商店没有任何加载 我做错了什么? 提前致谢

2 个答案:

答案 0 :(得分:0)

是的,感谢您的帮助,解决原因是,存储数据是异步加载的。加载数据的代码应该是:

allFilmGenresStore.load({ 
    callback : function(records, options, success) { 
        // some custom logik 
    } 
});

答案 1 :(得分:0)

你必须改变读者

reader: {
            type: 'json',
            root: 'root'
        }

并发送json_encode('root' => $data);

我希望它能帮到你