dimanche 30 juillet 2017

Cannot convert object to primitive value at Array.toString (native) when populating ember-power-select with array of objects generated dynamically

I need to populate a power-select with objects from the store, but I can only get the options displayed with the hard coded arraymyOptions. I tried to generate myOption2 dynamically, and apparently got the same output as myOptions, but it throws an error:

ember.debug.js:19845 Uncaught TypeError: Cannot convert object to primitive value
at Array.toString (native)
at Object.addListener (http://localhost:4200/assets/vendor.js:30682:88)
at Object.addObserver (http://localhost:4200/assets/vendor.js:34026:23)
at Array.addObserver (http://localhost:4200/assets/vendor.js:47679:27)
at Class.updateOptions (http://localhost:4200/assets/vendor.js:88968:17)
at invoke (http://localhost:4200/assets/vendor.js:11825:16)
at Queue.flush (http://localhost:4200/assets/vendor.js:11891:11)
at DeferredActionQueues.flush (http://localhost:4200/assets/vendor.js:11699:17)
at Backburner.end (http://localhost:4200/assets/vendor.js:11013:25)
at Backburner.run (http://localhost:4200/assets/vendor.js:11135:18)


function addListener(obj, eventName, target, method, once) {
_emberMetalDebug.assert('You must pass at least an object and event name to Ember.addListener', !!obj && !!eventName);
_emberMetalDebug.deprecate('didInitAttrs called in ' + (obj && obj.toString && obj.toString()) + '.', eventName !== 'didInitAttrs', {
  id: 'ember-views.did-init-attrs',
  until: '3.0.0',
  url: 'http://ift.tt/2hdVPlZ'
});


//template.hbs


  


//component.js

myOptions: [
  { id: 1, name: 'First Option' },
  { id: 2, name: 'Second Option' }
],

myOptions2: [],

didReceiveAttrs() {
  this.get('model.content').forEach((option) => {
    this.get('myOptions2').push(option._data);
  });
}


//#=> myOptions: [{id: 1, name: 'First Option'},{"id":2,"name":"Second Option"}]
//#=> myOptions2 [{id: 1, name: 'First Option'},{"id":2,"name":"Second Option"}]





Aucun commentaire:

Enregistrer un commentaire