3

Ember.js / rendering network content nested on the handlebars

 2 years ago
source link: https://www.codesd.com/item/ember-js-rendering-network-content-nested-on-the-handlebars.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Ember.js / rendering network content nested on the handlebars

advertisements

I have a model 'transaction' in which an array of subCategories is declared. This array is populated with transaction type objects whenever the method 'add_subcagtegory' of transactionsController is called. Now when i try to render subcategories in a nested loop(#collection), i do not get it done. The outer loop(#each) that is rendering the array controller objects is working fine. Can anyone tell how to render the subCategories array?

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 the template:

<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 the template under collection,How can I access subCategories?

http://jsfiddle.net/KbN47/29/


Does simply binding the content of the {{collection}} helper to this.subcategories (this is a transaction in your context) work ?

{{#collection contentBinding="this.subcategories"}}

Update

Here is a jsfiddle: http://jsfiddle.net/Sly7/tRbZC/

Please note the ember version is the latest-one. You should update, as the 0.9.5 is very old. I didn't have a look of the <select> behavior, but if it does'nt work, I think you have now all the keys to make it works :)

Tags ember.js

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK