Search code examples
kendo-uikendo-dropdown

kendo MVVM data-bind dropdownlist


How can I bind a local array to the MVVM dropdownlist of kendo.

I have an array like this

var array = [0.0, 20.00]

and I want to bind it to my input control

<input data-role="dropdownlist"
       data-bind='"source: ' + array + '"' />

Its not working. Any ideas how I can achieve this?

thanks


Solution

  • It's hard to tell from your question whether you have forgotten to use kendo.bind() to bind the View to the ViewModel but I suggest you also review the Kendo UI Framework Source Binding documentation for the syntax of data-bind. Also check the DropDownList MVVM Demo for a more complete example. A minimalist implementation is shown below:

    <body id="appRoot">
      <p>Minimalist DropDownList example</p>
      <input data-role="dropdownlist" data-bind="source: array">
      <script>
        // Ideally you would use this viewModel variable instead of the plain JavaScript object literal below
        var viewModel = kendo.observable( { array: [ 0.0, 20.00 ] } );
    
        kendo.bind($("#appRoot"), { array: [ 0.0, 20.00 ] } );
      </script>
    </body>