ember.js - logger - ¿Es posible observar arreglos dentro de matrices usando @each?
emberjs input (1)
Agregue otro @each
a la lista de propiedades .property(''things.@each.subthings.@each.length'')
Tengo un controlador que contiene una serie de "cosas". Dentro de cada una de estas cosas hay una serie de "subtaciones". Me gustaría crear una propiedad calculada que contenga todas las subclases en todas las cosas (una matriz aplanada de subprocesos).
Mi propiedad calculada depende de things.@each.subthings.length
. Encuentro que si establezco las propiedades de los subthings
de una cosa, mi propiedad calculada se actualiza. Sin embargo, si llamo pushObjects
para agregar nuevos datos a mi matriz de subthings
existente , mi propiedad calculada no se actualiza.
Creé un jsfiddle para demostrar. El código es el siguiente:
App = Em.Application.create({});
App.controller = Em.Object.create({
things: [
Em.Object.create({subthings:[]}),
Em.Object.create({subthings:[]}),
Em.Object.create({subthings:[]})
],
allSubThings : function() {
var things = this.get(''things'');
var results = [];
things.forEach( function(thing) {
results.pushObjects( thing.get(''subthings'') );
});
return results;
}.property(''things.@each.subthings.length'').cacheable()
});
setTimeout(function() {
var things = App.controller.get(''things'');
// This works:
things.objectAt(0).set(''subthings'',[1,2,3]);
}, 1000);
setTimeout(function() {
var things = App.controller.get(''things'');
// This does not:
things.objectAt(1).get(''subthings'').pushObjects([1,2,3]);
}, 2000);
¡Gracias!