Search code examples
javascriptangularjskendo-uikendo-mobile

Updating `ObservableArray` Item which is in json format


I have Kendo ObservableArray, I am adding json values to this array.

var array = new kendo.data.ObservableArray([]);
array.bind("change", function(e) 
{
    console.log("action: ["+e.action+"]  index:["+e.index+"] items:["+e.items+"]");

    // Do some calculations and then: 
    // 1. Set the calculated result to "result" variable
    // 2. Update "isDone" value to "true"

});

for(var index=0;index<5; index++)
{
    var object = new Object();
    object.name = "XYZ:"+index;
    object.id = index;
    object.isDone = false;
    object.result = 0;

    array.push(object);  
}

I am observing changes to this array, and once any I get event for item added to array, then I do some calculations/processing.

Once after processing I want to update values for newly added object.
How should I do that?


Solution

  • The good way to change items content in Kendo UI observable object or array is to use "set" method. To get the content use the "get" method.

    array[0].set("name", "new name");
    

    Check example here:

    http://dojo.telerik.com/ADAHi

    Also check the documentation from Telerik Kendo UI site to get the idea;

    http://docs.telerik.com/kendo-ui/api/javascript/data/observableobject#methods-set

    set Sets the value of the specified field.

    PARAMETERS name String The name of the field whose value is going to be returned.

    value Number |String |Date |Object The new value of the field.