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

kendo.bind with nested elements with data-role attribute

2 Answers 154 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Jaap
Top achievements
Rank 2
Jaap asked on 08 Mar 2012, 10:16 AM
Suppose I have this markup:
<div id="myID">
    <div data-role="tabstrip">
        <ul>
            <li>tab1</li>
            <li>tab2</li>
        </ul>
        <div>
            Content tab 2
            <select data-role="dropdownlist" data-source='{"transport":{"read":"some-url"}}' />
        </div>
        <div>
            Content tab 2
        </div>
    </div>
</div>


When I bind this to a viewmodel

kendo.bind("#myID", viewModel);

then the dropdownlist is initiate twice (and as an effect two requests are done to the server).

This is caused by the fact that kendo.bind iterates through all child elements and calls bindElement for each element (which is ok). The bindElement function looks if the element has a data-role attribute, if so it calls bindingTargetForRole which calls kendo.init(..).
This kendo.init() does a jQuery query for all child elements with a data-role attribute including itsself and initializes each child element.

So in my example when kendo.bind calls bindElement for the tabstrip, the creation of the tabStrip widget causes the dropDownList widget also to be created.
But then kendo.bind iterates further and calls bindElement for the select element and then again the dropDownList widget is created.

I guess this should not be done twice.

Regards, Jaap

2 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 08 Mar 2012, 10:55 AM
Hello,

 You are absolutely right. We will fix that in the official release.

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!
0
Jaap
Top achievements
Rank 2
answered on 26 Mar 2012, 09:05 AM
I can confirm this is fixed in the release version.
Thanks, Jaap
Tags
MVVM
Asked by
Jaap
Top achievements
Rank 2
Answers by
Atanas Korchev
Telerik team
Jaap
Top achievements
Rank 2
Share this question
or