Getting the model variable value

2 posts, 0 answers
  1. Iram
    Iram avatar
    9 posts
    Member since:
    Apr 2015

    Posted 10 Jun 2015 Link to this post

    Hello,

     

    Based on the window APP model given below, I would like to get the value of searchContacts in my read function. Could someone possibly point out to me on how I can achieve that?

     
    (function () {
        // store a reference to the application object that will be created
        // later on so that we can use it if need be
        //var app;
        // create an object to store the models for each view
        window.APP = {
            models: {
                home: {
                    title: 'Home'
                },
                settings: {
                    title: 'Settings'
                },
                contacts: {
                    model: {
                        searchContacts: '' // How can I get this value in the read function(options) area
                    },
                    title: 'Contacts',
                    ds: new kendo.data.DataSource({
                        transport: {
                            read: function (options) {
                                // implement the datasource here
    // how can I get the value of searchContacts from my model?
                                var searchCont = $("#searchContacts").val(); // Any other way?
     
    ....
    }}}); }}));

     

    Cheers.

     

    Best Regards,

    IK

  2. Tsvetina
    Admin
    Tsvetina avatar
    1873 posts

    Posted 12 Jun 2015 Link to this post

    Hi Iram,

    Try the following:
    (function () {
        // store a reference to the application object that will be created
        // later on so that we can use it if need be
        //var app;
        // create an object to store the models for each view
        window.APP = {
            models: {
                home: {
                    title: 'Home'
                },
                settings: {
                    title: 'Settings'
                },
                contacts: {
                    model: kendo.observable({
                        searchContacts: ''
                        title: 'Contacts',
                        ds: new kendo.data.DataSource({
                            transport: {
                                read: function (options) {
                                    var searchCont = window.APP.models.contacts.model.get("searchContacts");
                    })
                ....

    You can consider removing the model object and making contacts an observable object (the model) that contains all bound values (you do not seem to need the additional level of nesting objects).

    Additionally, to ensure that searchContacts is correctly updated when you change it, make sure you use set("searchContacts", value) to set the new value.

    To learn more about the Kendo ObservableObject and MVVM, check this article:
    ObservableObject in Kendo UI


    Regards,
    Tsvetina
    Telerik
     

    Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

     
Back to Top