我有一個模型'事務',其中聲明瞭一個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