I am trying to define a dataModel something like this:
var MyDataModel = kendo.data.Model.define({
id: "id",
fields: {
name: {
type: "string"
},
myListOfThings: {
defaultValue: []
},
numberOfThings: {
type: "number",
}
}
});
What I want though is something more. I was wondering if there is a way to define “derived properties” in the model type. More specifically I want numberOfThings to always compute to the length of the array myListOfThings.
That is I want the ability create the object like:
var o = new MyDataModel({ name: "a name", myListOfThings: ['a','b','c']});
And then having a kendo widget with a column bound to numberOfThings displaying 3.
Do you know how to accomplish this?
Edit:
Thanks Atanas, your answer works.
I was able to edit the jsbin code to a declarative binding form that works for me.
I’m not quite there yet thought since in my solution code I am getting a javscript error at line 269 in kendo.all.js that reads
return new Function(argumentName, functionBody);
The error message is
“ReferenceError: count is not defined”
I’m trying to find where my code differs from the jsbin code. .. but if you have an idea of what might be the problem I am all ears. If not, no worries, thanks for the answer.
Use a function which will return the number of items. Here is an example: http://jsbin.com/ategub/1/edit