我有以下模板:
{{#each item in controller.pagedAutomationExceptions}}
{{log item}}
<tr {{bindAttr class="item.rowClass"}}>
<td class="text-center">{{unbound item.BTicket}}</td>
<td>{{unbound item.Reason}}</td>
<td>{{unbound item.TimeReceived}}</td>
<td>
{{#if item.ShowContactVoltageSources}}
{{view Ember.Select
contentBinding="controller.contactVoltageSources"
optionValuePath="content.Name"
optionLabelPath="content.Name"
valueBinding="item.AutomationValue"
prompt="Choose one..."}}
{{/if}}
{{#if item.ShowVoltageField}}
{{view Ember.TextField valueBinding="item.AutomationValue"}}
{{/if}}
{{#if item.ShowEnergizedObjects}}
{{view Ember.Select
contentBinding="controller.energizedObjects"
optionValuePath="content.Name"
optionLabelPath="content.Name"
valueBinding="item.AutomationValue"
prompt="Choose one..."}}
{{/if}}
</td>
<td>
{{#if item.Errored}}
{{/if}}
{{#if item.IsUpdating}}
<btn class="btn btn-primary" disabled="disabled">
Updating..
</btn>
{{else}}
<btn {{action updateAutomationException item target="controller"}}
class="btn btn-primary">
Update
</btn>
{{/if}}
</td>
</tr>
{{/each}}
一切都按预期工作,但当我尝试更改路线时,我收到以下错误:
未捕获的TypeError:无法读取未定义的属性'IsUpdating'
如果我删除该行,那么还有一些其他属性无法读取。我不确定发生了什么,显然ember以某种方式获取未定义的对象,但我不知道如何,我实例化我的每一个对象并将它们推送到数组上。
这是控制器(对不起,如果它不准确,我离开工作,所以我从记忆中做到这一点,我也改变了大约一百万次尝试解决问题,这就是为什么我不认为问题是在那里):
App.Exception = Ember.Object.extend({
// properties used in template, etc..
});
App.ExceptionsController = Ember.Controller.extend({
init: function () {
this._super();
// ajax request to get exceptions from database
// once inspections are loaded
// set(automationExceptions, response)
// loadMoreExceptions()
},
automationExceptions: [],
pagedAutomationExceptions: Ember.A(),
loadMoreExceptions: function () {
// i have a variable that i store to tell me
// how many exceptions I'm currently showing.
// If there are more, I just add to this variable
// the paging amount, and for those elements
// create a new exception and add it to the
// paged array. This method also seems to work
// because I get more records on the view.
for (; currentTake < newTake; ++currentTake) {
var simple = automationExceptions[currentTake];
this.get('pagedAutomationExceptions').pushObject(
App.Exception.create(simple));
}
},
updateAutomationException: function () {
// ajax post update, this works fine..
}
});