Template binding within a for loop

0 Answers 176 Views
Templates
SpanTag
Top achievements
Rank 1
SpanTag asked on 18 Dec 2021, 11:30 PM | edited on 18 Dec 2021, 11:32 PM

Hi,

I have tried this every way I can think of. I am having problems with setting data-bind while iterating an array.
Made a small demo below, the actual code is much more complex and that is the reason I need to use the for loop in order to get the correct result.

How can I set the data-bind property on the input correctly?

 

  <div id="container">
    <div id="weekdays" data-template="weekday" data-bind="source : this"></div>
  </div>
          
  <script id="weekday" type="text-x-kendo-template">
     <div>
    # for (i = 0; i < data.lines.length; i++) { #
    	<h2>#: data.lines[i].day #</h2>
    	<input type="text" data-bind="value: data.lines[i].quantity" />
    # } #
    </div>
  </script>
  <script>
  $(document).ready(function () {
      var vm = kendo.observable({
        lines: new kendo.data.ObservableArray([
           { id: 123, day: "Monday", quantity: 5 },
           { id: 322, day: "Tuesday", quantity: 2 }
        ])
  });
  kendo.bind($("#container"), vm);
 });
</script>


SpanTag
Top achievements
Rank 1
commented on 19 Dec 2021, 10:05 PM

For future reference, this did the trick;

<input type="text" data-bind="value: lines[#:i#].quantity" />

No answers yet. Maybe you can help?

Tags
Templates
Asked by
SpanTag
Top achievements
Rank 1
Share this question
or