【问题标题】:Lazy load hasMany association in ExtJSExtJS中的延迟加载hasMany关联
【发布时间】:2013-04-18 06:41:18
【问题描述】:

我正在尝试在 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/

任何建议都会有所帮助。

【问题讨论】:

    标签: javascript extjs extjs4


    【解决方案1】:

    1。 hasMany 属性是一个数组

    1. 需要在hasMany关系上设置foreignKey,并在Post上提供外键字段

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-07
      • 1970-01-01
      • 1970-01-01
      • 2020-02-22
      • 2014-01-15
      • 1970-01-01
      • 2020-02-23
      • 1970-01-01
      相关资源
      最近更新 更多