我有一个模型'事务',其中声明了一个subCategories数组。只要调用transactionsController的方法'add_subcagtegory',该数组就会填充事务类型对象。现在,当我尝试在嵌套循环(#collection)中呈现子类别时,我没有完成它。渲染数组控制器对象的外部循环(#each)工作正常。任何人都可以告诉如何呈现subCategories数组?Ember.js /呈现在把手上的嵌套数组内容
app.js
App.transaction=Em.Object.extend({
account:null,
date:null,
source:null,
description:null,
category:null,
flag_for_later:null,
amount:null,
category_id:null,
record_index:null,
isSubCategory:null,
subCategories:[]
});
App.transactionsController = Em.ArrayController.create({
content: [],
add_subcategory: function(param){
var records=this.toArray();
if (typeof(records[param.value -1].subCategories) === "undefined") {
records[param.value -1].subCategories = new Array();
}
var category=App.transaction.create({
account:"//",
date:"//",
source:"//",
description:"//",
category:" ",
flag_for_later:" ",
amount:null,
category_id:records[param.value -1].subCategories.length + 1,
isSubCategory:true
});
records[param.value -1].subCategories.push(category);
App.transactionsController.set('content',[]);
App.transactionsController.pushObjects(records);
App.array.push(obj1);
}
});
和模板:
<table>
{{#each App.transactionsController}}
<tr>
<td>{{account}}</td>
<td>{{date}}</td>
<td>{{source}}</td>
<td>{{view App.TextField class="span12" style="border:0px;" objcount=record_index fieldname="description" value=description}}</td>
<td>{{view App.TextField class="span12" style="border:0px;" objcount=record_index fieldname="category" value=category }}</td>
<td><button onclick="App.transactionsController.add_subcategory(this);" value="{{unbound record_index}}">+</button></td>
<td>{{view App.TextField class="span6" style="border:0px;" objcount=record_index fieldname="flag_for_later" value=flag_for_later }}</td>
<td>{{amount}}</td>
</tr>
{{#collection contentBinding="App.transactionsController.subCategories"}}
<b>content does,nt not render</b>
{{/collection}}
{{/each}}
</table>
下收集模板
,如何访问子类别?
没有错误,但仍然没有,NT工作 – Zed 2012-08-03 09:49:13
这很奇怪,因为你定义子类别作为交易对象的数组...你可以发布您的代码的的jsfiddle? – 2012-08-03 09:50:57
好吧,看起来像add_category功能是越野车。我今天下午去看看。你可以用jsfidlle编辑你的问题,或者至少说明你如何使用这个函数? – 2012-08-03 10:02:05