Search code examples
jquerykendo-uitelerik

How to update data used by kendo.observable object using function in it? Kendo UI


Issue is my employeename is not updating with new values. When first time page hits it binds the correct value but after updating the name it does not update with updated employeename. EmpdataSource is updating but not function employeename

<div><ul> <li><span class="name"
                      data-bind="text: employeename" ></span></li></ul></div>

var viewModel = kendo.observable({ EmpdataSource: ActPst[ID].ptdata, employeename: function () {
        if (ActPst[ID].ptdata.data()[0].id < 0) {
            return ''
        } else {            
            return ActPst[ID].ptdata.data()[0].id
        }
    },

});

How can we update the employeename function in everytime the data gets updated?


Solution

  • Try this:

    if (this.get("ActPst[ID].ptdata.data()[0].id") < 0) {
        return ''
    } else {            
        return this.get("ActPst[ID].ptdata.data()[0].id")
    }
    

    You need to use get() in bound functions in order for changes to trigger a binding update.