This is a migrated thread and some comments may be shown as answers.

Getting the model variable value

1 Answer 55 Views
AppBuilder in-browser client
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Iram
Top achievements
Rank 2
Iram asked on 10 Jun 2015, 10:52 AM
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

1 Answer, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 12 Jun 2015, 08:20 AM
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.

 
Tags
AppBuilder in-browser client
Asked by
Iram
Top achievements
Rank 2
Answers by
Tsvetina
Telerik team
Share this question
or