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

4 posts, 0 answers
  1. Yuan
    Yuan avatar
    9 posts
    Member since:
    Jul 2014

    Posted 18 Jun 2015 Link to this post

    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>

  2. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2565 posts

    Posted 22 Jun 2015 Link to this post

    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!
     
  3. Kendo UI is VS 2017 Ready
  4. Yuan
    Yuan avatar
    9 posts
    Member since:
    Jul 2014

    Posted 22 Jun 2015 in reply to Kiril Nikolov Link to this post

    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.
  5. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2565 posts

    Posted 24 Jun 2015 Link to this post

    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!
     
Back to Top
Kendo UI is VS 2017 Ready