I have a transaction model in which an array of subcategories is declared. This array is populated with transaction type objects whenever the add_subcagtegory of transactionController method is called. Now when I try to display subcategories in a nested loop (#collection), I am not doing this. An outer loop (#each) that renders array controller objects works fine. Can anyone tell how to display an array of subcategories?
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); } });
and pattern:
<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>
in a subfolder of the template, How can I access the subcategories?
http://jsfiddle.net/KbN47/29/
source share