簡體   English   中英

延遲加載在ExtJS中具有hasMany關聯

[英]Lazy load hasMany association in ExtJS

我正在嘗試像以下示例一樣在ExtJS 4中實現延遲加載: http : //dev.sencha.com/deploy/ext-4.0.0/examples/data/associations.html使用以下代碼:

/* 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"}]

但是返回的Posts-Store始終為空(0條記錄)。 您可以在這里檢查我的JSFiddle: http : //jsfiddle.net/lenoxDoe/n6Xbw/2/

任何意見將是有益的。

1. hasMany屬性是一個數組

  1. 您需要在hasMany關系上設置foreignKey ,並在Post上提供一個外鍵字段

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM