1

我是 Ember 的新手,我对显示 hasMany 关系有疑问。

我的模型:

App.Shop = DS.Model.extend({
                name:           DS.attr('string'),
                openSettings:   DS.hasMany('App.OpenSetting')
});
App.OpenSetting = DS.Model.extend({
                title:          DS.attr('string'),
                data:           DS.attr('string'),
                shopId:         DS.belongsTo('App.Shop')
});

我有映射:

DS.RESTAdapter.map('App.Shop', { 
    openSettings:   { key: 'openSettings' }
});
DS.RESTAdapter.map('App.OpenSetting', { 
    shopId:         { key: 'shopId' }
});

在脚本中的 index.html 中,我有:

{{#each model}}
   {{id}} - {{name}} # 
   {{#each openSettings}}
       {{title}}                 
   {{/each}}
{{/each}}

但是当对象商店在 openSettings (openSettings:[1,2]) 中有一些关系时,我得到错误:

未捕获的 RangeError:超出最大调用堆栈大小

我做错了什么?

夹具:

    App.Shop.FIXTURES = [
        {
            name: "Supermarket",
            id: 2,
            openSettings: [
                2, 5
            ]
        }
    ];

    App.OpenSetting.FIXTURES = [
        {
            title: "monday - friday",
            data: "8:00 - 24:00",
            id: 2,
            shopId: 2
        },
        {
            title: "saturday",
            data: "8:00 - 1:00",
            id: 5,
            shopId: 2
        }
    ];

感谢帮助。

4

1 回答 1

6

当字段命名为“数据”时,Ember 会引发该错误。更改后,一切正常。

于 2013-05-14T08:46:28.637 回答