lundi 3 juillet 2017

Setting Scope/Binding/this in Ember.computed.map

I was wondering if it was possible to bind the scope of this inside of an Ember.computed.map function to be scoped to the model instance rather than the module itself.

For example, I would like to write something like: export default Ember.model.extend({ property1: valueWhichChangesWithModel1, property2: valueWhichChangesWithModel2, helperProperty: Ember.computed('property1', function () { const property = this.get('property1'); return [whatever(property)]; }) mapFunction: Ember.computed.map('helperProperty', function (value, index) { return stuff(value, this.get('property2')); }) }) However, the this.get('property2') always fails because this is bound to the module, not the model object.

All kind of normal binding tricks I have tried have not given me access to the model instance, e.g. to us bind or apply in different places on the function. I am not sure if I just didn't happen to find the right place to put it, if there is another workaround, or if this is just known to be impossible. I could not find any references for how to approach this in Ember's documentation either. Thanks for any advice anyone may have!




Aucun commentaire:

Enregistrer un commentaire