I'm trying to achieve something like this:
for (var i = 0; i < types.length; i++) {
var type = types[i];
myObj()['text' + type.name] = ko.computed(function () {
return myFuction(myObj()[type.name + 'MyText']());
});
}
If that's not clear, I have a certain object type, for which I am trying to achieve maximum flexibility. Namely, I want to be able to add a new attribute to my object in the DB, without having to change the client side code.
This works fine except when it comes to computed variables. In the above example, the function seems to always be called on the last value of type, ie the last value of the array.
Anyone has a solution to this issue?
Example:
types = [{name: 'red'}, {name: 'green'}, {name: 'blue'}];
In the end, myFunction and thus the computed variable always gets called on {name: blue} Hope this is kinda clear...