Setting a value from a function

2 posts, 0 answers
  1. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 08 May 2012 Link to this post

    Here's the scenario...I have a button on my model....essentially a toggle.  However the model STATE should only change if the $.ajax call returns success...so this is what I tried

    viewModel = kendo.observable({
            releaseMe: function (item) {
                release(item);
            }   
        });
     
    function release(item) {
        var releaseState = item.data.Released;
        var campus = item.data.CampusID;
        var block = viewModel.BlockID;
        var url = "/api/cps/clerkship/blocks/" + block +  "/" + campus + "/";
     
        if (!releaseState)
            url += "release";
        else
            url += "unrelease";
     
     
        $.ajax({
            url: url,
            type: "PUT",
            data: {
                id: block,
                campus: campus
            },
            success: function (e) {
                if (!releaseState)
                    item.set("Released", true); //WHAT SHOULD THIS BE
                else
                    item.set("Released", false); //WHAT SHOULD THIS BE
            }
        });
    }

    Any idea?  Should it literally just be a simple
    item.data.Released = true;
  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 10 May 2012 Link to this post

    Hi,

     To set a field you should use the set method. If you want to set item.data.Released then use this
    item.set("data.Released", true). This is mentioned in the ObservableObject help topic.

    Regards,
    Atanas Korchev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Kendo UI is VS 2017 Ready
Back to Top