Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to bind content with JSON in Ember.js
    primarykey
    data
    text
    <p>All the examples are using fixed data source in the arraycontroller.content, while I am using dynamic data source which is generated from anther web service and returns a JSON, it won't create an object that I declared in Ember, here is the code sample:</p> <pre><code> ET.AppYear = Ember.Object.extend({ text:null, value:null }); ET.EmailTypes = Ember.Object.extend(); ET.appYearController = Ember.ArrayController.create({ content: [], loadYears: function (year) { if (year != null) { for (var i = -5; i &lt; 5; i++) { this.pushObject({ text: year + i, value: year + i }); //.AppYear.create({ text: year + i, value: year + i }); } } } }); ET.selectedAppYearController = Ember.Object.create({ selectedAppYear: '2011', alertChange: function(){ alert("selected App Year is now " + this.get('selectedAppYear')); }.observes('selectedAppYear'), isChanged: function () { if (this.appYear != null) { this.set('selection',this.get('content')); //LoadETByAppYearETTypeID(this.selectedAppYear, ET.selectedEmailTypesController.emailType.email_template_type_id); } } .observes('selectedAppYear'), AppYear: function() { var ay = ET.appYearController.findProperty('text',this.get('selectedAppYear')); return ay; }.property('selectedAppYear') }); </code></pre> <p>As you can see, I will call <code>ET.appYearController.loadYears</code>(JSON) in an AJAX post back, which will create the content by using <code>this.pushObject</code>, but this is not the <code>ET.AppYear</code> object schema, while I call <code>ET.selectedAppYearController.selectedAppYear</code>, it returns an undefined object, and which really returns an object with <code>{text:xx,value,xx}</code> schema. That's why the <code>selectionBinding</code> also won't work in this case. </p> <p>So what's the typical solution for this to import JSON elements as defined object and put into content?! </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload