0

我在 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'
        }
    }
});

所以,在执行上面的代码之后:

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

方法

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

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

4

2 回答 2

0

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

allFilmGenresStore.load({ 
    callback : function(records, options, success) { 
        // some custom logik 
    } 
});
于 2013-08-16T19:42:38.980 回答
0

你必须改变阅读器

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

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

我希望它会帮助你

于 2014-06-18T15:48:14.723 回答