1

I'm trying to implementing Lazy loading in ExtJS 4 like this example: http://dev.sencha.com/deploy/ext-4.0.0/examples/data/associations.html using this Code:

/* Models */
Ext.define('Post', { 
    extend: 'Ext.data.Model', 
    fields: ['title'], 
    proxy: {
        type: 'ajax', 
        url: 'http://example.com/post.json'
    }
});

Ext.define('User', { 
    extend: 'Ext.data.Model', 
    fields: ['name'], 
    hasMany: 'Post', 
    proxy: { 
    type: 'ajax', 
        url : 'http://example.com/user.json'
    } 
});

/* Load User and Posts */
User.load(1, {
    success: function(user) {
        var test = user.posts();
        test.on('load', function(me) {
            console.log(me.getCount()); /* THIS is always 0?! */
        });
        test.load();
    }
});

/* Returned JSON Data */

/* User */
[{"name":"blalala"}]

/* Posts */
[{"title":"dfgdfgdgd"}]

but the returned Posts-Store is always empty (0 Records). You can check my JSFiddle here: http://jsfiddle.net/lenoxDoe/n6Xbw/2/

Any advice would be helpful.

4

1 回答 1

2

1. hasMany 属性是一个数组

  1. 您需要在 hasMany 关系上设置键,并在 Post 上提供外键字段
于 2013-04-17T20:05:54.470 回答