2013-07-31 13 views
6
self.resultList.forEach(function(item, index, enumerable){ 
         console.log(self.resultList); 
         item.id=11; 
         item.get('id'); 
        }); 

la voce in questo modo: enter image description herecome modificare il valore con Ember.js Array forEach?

se item.id = 11; eccezione in questo modo:

Assertion failed: You must use Ember.set() to access this property (of [object Object])

così item.get ('id') o item.set ('id', 11)

eccezione come questo

Uncaught TypeError: Object # has no method 'get'

questo oggetto non è l'Oggetto di Braci? Quindi qual è l'oggetto?

Qualcuno potrebbe dirmi come cambiare il 'valore del itme.id ..

Un milione di Grazie

+1

Cosa c'è dentro self.resultList? Penso che la matrice contenga sia oggetti JS semplici che oggetti d'oro. – mavilein

risposta

21

È possibile utilizzare la Ember.set(yourObject, propertyName, value); e Ember.get(yourObject, propertyName); per impostare in modo sicuro e ottenere le proprietà.

Nel tuo caso:

self.resultList.forEach(function(item, index, enumerable) { 
    Ember.set(item, "id", 11); 
    Ember.get(item, "id"); 
}); 
+0

non funziona .. – seagod

+0

Qualche errore ricevuto? –

+0

l'eccezione come questa: È necessario utilizzare Ember.set() per accedere a questa proprietà (di [oggetto oggetto]) – seagod

0

Nel mio caso l'ho fatto in questo modo

//In my controller I've defined the array 
 
displayInfoCheckboxes: [ 
 
    { 
 
     turnover: { 
 
     label: "Turnover", 
 
     value: 1, 
 
     propertyName: "turnover" 
 
     } 
 
    }, { 
 
     pl: { 
 
     label: "P&L", 
 
     value: 1 
 
     } 
 
    } 
 
] 
 

 
//and in my handler I passed the full string path to the property in the set method 
 

 
let displayInfoCheckboxes = this.get('displayInfoCheckboxes'); 
 
let controller = this; 
 

 
displayInfoCheckboxes.forEach(function(items,index) { 
 
    for (var key in items) { 
 
    controller.set('displayInfoCheckboxes.' + index + '.' + key + '.value', false); 
 
    } 
 
})

Problemi correlati