I've written this Mixin for my AdminController so that I can edit a Record's data. I'm collecting the model attributes into an array that is returned. I'm binding the value, but to do so I've added a reference to the model in each array item. I'm worried that doing this is going to leak memory. Ideally I can reference the model with some other (more global?) path.
Here is the Mixin:
import Ember from 'ember';
export default Ember.Mixin.create({
modelAttributes: function() {
var model = this.get('model');
var attrs = [];
model.eachAttribute(name => {
var obj = Ember.Object.create({
// Possible memory leak because I've assigned the model inside a closure?
model: model,
key: name,
// This is connects the model attribute with the input
// field in my template
valueBinding: ('model.'+name),
});
attrs.push(obj);
});
return attrs;
}.property('model'),
});
This is how I'm utilizing the attributes in a template:
{{#each attr in modelAttributes}}
<tr>
<th>{{attr.key}}</th>
<td>{{input value=attr.value class="form-control"}}</td>
</tr>
{{/each}}
Code review and other ideas are welcome!!
Aucun commentaire:
Enregistrer un commentaire