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

Problem with data binding when using a Layout

2 Answers 130 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Allan
Top achievements
Rank 1
Allan asked on 26 Nov 2012, 01:28 PM
I'm trying to wrap my head around the data binding feature of kendo. I'm building a mobile app.
I use the following code for my databinding

var app = new kendo.mobile.Application(document.body);
    
    var dayViewModel = kendo.observable(
    {
        todayText: "_",
        showNextDay: function () {
            alert("next");
        },
        showPreviousDay: function () {
            alert("previous");
        }
    });


    kendo.bind($("#dayView"), dayViewModel, kendo.mobile.ui);

As soon as kendo.bind is invoked, the Layout is lost. If the view already has a header element specified, this element is shown instead. Why is this happening?

Also, I've tried a bit further, since the reason why I need to invoke kendo.bind manually, is that I want to load data into the viewModel from a ajax response. I've added the following code for the ajax request

$(function () {
        $.get("request_url", function (data) {
            dayViewModel.todayText = data.DayDescription;
            
            kendo.bind(document.body.children, dayViewModel, kendo.mobile.ui);
        });
    });

And it works just is intended, but I'm still not able to use my Layout. Although I've discovered that if I comment out the first call to kendo.bind, the Layout is applied. Although then the header grows to about double height. And I've got no custom styles or similar.

2 Answers, 1 is accepted

Sort by
0
Accepted
Petyo
Telerik team
answered on 27 Nov 2012, 11:54 AM
Hello Allan,

 Take a look at this help article for the recommended (and supported) approach for using Kendo UI Mobile with MVVM. You may look into the source code of the MVVM version of our sushi demo. 

Greetings,
Petyo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Allan
Top achievements
Rank 1
answered on 27 Nov 2012, 01:00 PM
The sample answers all of my questions!

But the getting started pieces are thin and leaves a lot of questions unanswered. You should make sure samples such as that is easily accesible - at least I've been through a lot of the docs and didn't notice this sample.

I'd encourage you to make more samples like that available :-)

Allan
Tags
General Discussions
Asked by
Allan
Top achievements
Rank 1
Answers by
Petyo
Telerik team
Allan
Top achievements
Rank 1
Share this question
or