2014-10-20 11 views
5

Etrafa baktım ama gerçek farklar aşağıdaki arasındaki farkların neler olduğunu ben herhangi iyi belgelerine bulamıyor:EmberJS'de [], @each, content ve <arrayName> arasındaki fark nedir?

Ember.Object.extend({ 
    // ... 
    myProperty1: function() { /* ... */ }.property('myArray'), 
    myProperty2: function() { /* ... */ }.property('myArray.content'), 
    myProperty3: function() { /* ... */ }.property('myArray.[]'), 
    myProperty4: function() { /* ... */ }.property('[email protected]') 
}); 

Ben .content özellik için dizinin dahili depolama, gibi görünüyor anlıyoruz ki Bu, PromiseArray olması durumunda kullanılamayabilir. Ayrıca bu şekilde @each'un kullanılmayacağını biliyorum, ancak çoğunlukla bu dizideki öğelerin her birinin iç özelliklerini eşleme sonucu elde edilen ProxyArray erişimini kullanmak. Bu ince farkların yanı sıra, hemen hemen aynı şekilde çalışıyor gibi görünüyorlar. Peki ya myArray ve myArray.[]? Peki ya diğerleri ile kaburga halinde? Ben de dikkat edeceğiz

cevap

3
Ember.Object.extend({ 
    // ... 

    // Updates if myArray is set to a new value using .set 
    myProperty1: function() { /* ... */ }.property('myArray'), 

    // Updates if myArray is an Ember Object (like an ArrayController) 
    // and its 'content' property is set to a new value using 
    // .set('content', newArray) or .replaceContent(...) 
    // which can also happen implicitly 
    // Also note that for an ArrayController 'content' is an alias of 'model' 
    myProperty2: function() { /* ... */ }.property('myArray.content'), 

    // Updates if myArray is an Ember Array or ArrayProxy or MutableEnumerable 
    // and it is 'mutated' using myArray.addObject(s), myArray.removeObject, 
    // myArray.popObject, myArray.shiftObject, myArray.pushObject(s), etc. 
    myProperty3: function() { /* ... */ }.property('myArray.[]'), 

    // Updates if myArray is an Ember Array or ArrayProxy and one of it's 
    // elements is set to a new value using .set or .replace 
    // such as this.set('myArray.firstObject', 10) or 
    // this.get('myArray').replace(2, 1, [10]); 
    myProperty4: function() { /* ... */ }.property('[email protected]') 
}); 

o sen Sihirli Şehir yöntemlerden birini kullanın ve sadece bu gibi basit JavaScript kullanarak diziyi güncellemek için unutursanız: Bu hesaplanan özelliklerin

this.myArray = []; 

hiçbiri güncellenecektir.

+0

Etkileyici cevap. Doğru ve net. Çok teşekkür ederim. – Alpha