enyo.kind({ name: "customViewModel", kind: "enyo.Model", attributes: { prop1: null, prop2: null } }); enyo.kind({ name: "customView", model: new customViewModel(), components:[{name:"compA"}] bindings: [ { from: ".model.prop1", to: ".$.compA.content" } ] (…) })But when I try to use this kind in a repeater, something wrong happens to the model data. All the views display the same info as the last kind object. It’s like there is the same instance view/model to all the repeated views.
enyo.kind({ name: "mainView", components: [ { name: "repXPTO", kind: "enyo.DataRepeater", components: [{ components: [{ kind: "customView", name: "cvItem" }], bindings: [ { from: ".model.prop1", to: ".$.cvItem.model.prop1" }, { from: ".model.prop1", to: ".$.cvItem.model.prop1" } ] }] } ], startApp: function () { var collToBind = new Array(); for (var i = 1; i < 6; i++) { collToBind.push(new customViewModel({ prop1: i, prop2: (i+i) })); } this.set(".$.repXPTO.collection", new enyo.Collection(collToBind)); } });All de items in the repeater display de number 5, and not 0, 1, 2, 3, 4, 5 as expected.
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
That is the result.
It almost looks like after every item created by the repeater, when the bind occurs, its somehow connected to de previous models!
I have tried what you said and nothing
If you notice, i'm printing the control ID (euid) and its always different.
That makes me think that in fact is another instance of my view.
What is the use of creating kinds if we are not able to use them multiple times?
I am surely doing something wrong.
Here is the fiddle
http://jsfiddle.net/ahelleno/tc0y6x2r/10/
http://jsfiddle.net/u5ydLsjd/1/
Prob something do with flyweight pattern to improve performance but I'd have to look at enyo source code to confirm/deny that.
In the line 18: Is that what you expect?
Hope it helps.
So, for further reference, here is the working fiddler: http://jsfiddle.net/u5ydLsjd/1/
By the way, is there any "mark as resolved" button in this forums?
model: new customViewModel(),
You might want to create the model in the constructor if you want it to be unique for each custom view. Your binding in the DataRepeater does overwrite the custom view's model, of course.