Populating Ember.Select view contents from RecordArray retrieved using Ember data

I have a select list that is created using this code:

      {{view Ember.Select
      contentBinding="App.riskCategories"
      optionValuePath="content.id"
      optionLabelPath="content.name"
      selectionBinding="riskCategory"
      class="input-medium"}}

riskCategory is a property of the App.Facility model loaded for the template, and the App.RiskCategory list is populated with this code:

App.ready = function() {
  App.riskCategories = App.RiskCategory.all()
}

This works fine and populates the selection list, but only with a subset of the risk categories already loaded into the browser. If I call App.RiskCategory.find () from the browser console, the rest will be loaded and the selection list will be updated, but I can not get the code to work for this.

So I tried:

App.ready = function() {
  App.riskCategories = App.RiskCategory.find()
}

or

App.ready = function() {
  App.RiskCategory.find()
  App.riskCategories = App.RiskCategory.all()
}

But both of them lead to the following error:

Uncaught Error: Attempted to handle event `loadedData` on <App.Facility:ember417:1> while in state rootState.loaded.updated.uncommitted. Called with undefined

, . App.RiskCategory , db. App.Facility App.RiskCategories

!

+5
3

, App.Facility {{#if isLoaded}}

, :

{{#each client.facilities}}
  {{#if isLoaded}}
    {{view Ember.Select
      contentBinding="App.riskCategories"
      optionValuePath="content.id"
      optionLabelPath="content.name"
      selectionBinding="riskCategory"
      class="input-medium"}}
  {{/if}}
{{/each}}

, App.Facility, App.RiskCategory , ​​ App.RiskCategory, , dataLoaded , , .

+1

APP.YourRoute = Ember.Route.extend({
    setupController:function(controller,model) {
       this._super(controller,model);
       controller.set('riskCategories',App.RiskCategory.find());
    },  

});  

, , , :

{{view Ember.Select
  contentBinding="controller.riskCategories"
  optionValuePath="content.id"
  optionLabelPath="content.name"
  selectionBinding="riskCategory"
  class="input-medium"}}
+3

I had a similar problem, and a solution using #isLoadeddid not work for me. However, a property has been added promptfor the item Ember.Select. I suspect that this is due to the asynchronization of the visualization of the presentation and loading of data (in my case from FIXTURES, but as far as I know, it DS.FixtureAdapterimitates time delays when loading data).

0
source

All Articles