余烬 {{each}} 帮助程序未显示完整列表



我的模板:

{{#each lesson_types}}
    {{name}}: ${{price}}
{{/each}}
{{#view App.EnterFormView action="pushType"}}
    {{input value=currentName placeholder="Lesson Name"}} {{input value=currentPrice placeholder="Lesson Price"}}
{{/view}}
<button {{action "saveTypes"}}>Save</button>

问题出在那个{{each}}块上,它只呈现它的第一个条目。

pushType方法:

pushType: function() {
    console.log(this.get('lesson_types'));
    if (!this.get('lesson_types')) this.set('lesson_types', []);
    this.get('lesson_types').push(Ember.Object.create({name: this.get('currentName'), price: this.get('currentPrice')}));
    console.log(this.get('lesson_types'));
    this.setProperties({currentName: '', currentPrice: 0});
}

如果EnterFormView在具有焦点时按下 Enter 键,则只需在其父控制器上触发它的方法。

一切都很好,直到我以这种形式输入东西。如果我在这些输入中键入"Full"和"30",然后键入"Half"和"15",则每个输入中都会显示"Full"30",即使pushType控制台输出显示以下内容:

undefined
[Class, nextObject: function, firstObject: undefined, lastObject: undefined, contains: function, getEach: function…]
[Class, _super: undefined, nextObject: function, firstObject: undefined, lastObject: undefined, contains: function…]    
[Class, Class, _super: undefined, nextObject: function, firstObject: undefined, lastObject: undefined, contains: function…]

因此,您可以看到数组正在正常增长{{each}}只是没有显示所有条目。

值得指出的是,lesson_types是模型的属性

更新

这是扩展输出 http://pastebin.com/UrEutPxZ 的粘贴这奇怪地表明第二个对象与第一个对象不同。这是怎么回事?

你应该使用pushObject而不是push

推送不会通知余烬数组已更改

最新更新