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

How to bind value to multiple dropdowns (html select) within a template?

3 Answers 91 Views
Templates
This is a migrated thread and some comments may be shown as answers.
Yuan
Top achievements
Rank 1
Yuan asked on 18 Jun 2015, 07:38 PM

Hi, I have this viewModel, that I want to bind values with the dropdowns inside a template.

But I cannot bind the value 1, 3, 5 to the dropdowns, i.e. the selected value of the html selects.

 Could you please help with this?

<script type="text/x-kendo-template" id="totalAmountTemplate">
# for (int i = 0; i < values.length; i++) { #
<select data-bind="value: values[i]">#
for (int j = 0; j < values.length; j++) { #
<option>#= j #</option># } #</select>
# } #
</script>
<script>
var viewModel = kendo.observable({   
    data: { values: [1, 3, 5] }
});
kendo.bind(document.body.children, viewModel);
</script>
<div data-bind="source: data" data-template="totalAmountTemplate"></div>

3 Answers, 1 is accepted

Sort by
0
Kiril Nikolov
Telerik team
answered on 22 Jun 2015, 02:38 PM
Hi,

You can use source binding for select elements as well. Here is an example, based on your data:

http://dojo.telerik.com/EmAPi

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Yuan
Top achievements
Rank 1
answered on 22 Jun 2015, 02:41 PM
Actually, what I need is a bit different from this. In my first loop, I created a series of dropdowns, and then I'm trying to bind the values of the array to each of the dropdowns. Please note that it is the value I need to bind, rather than the source.
0
Kiril Nikolov
Telerik team
answered on 24 Jun 2015, 09:08 AM

Hello Yuan,

I am afraid that binding the value of an element that is created inside the template is not supported. 

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Templates
Asked by
Yuan
Top achievements
Rank 1
Answers by
Kiril Nikolov
Telerik team
Yuan
Top achievements
Rank 1
Share this question
or