knockout.js - Unable to work out simple helloworld example of KnockOut -


i trying use knockout despite simple code unable select list populated. below code, can point out doing wrong

<html> <head>     <script type="text/javascript" src="knockout-3.3.0.js"> </head> <body>     <script type="text/javascript">         var listeditorviewmodel = function () {         this.allitems = ko.observablearray(["apple"]);         }         ko.applybindings(document.body,new listeditorviewmodel());     </script>     <div>this select populated</div>     <select multiple="multiple" data-bind="options: allitems"></select> </body> </html> 

your parameter order in applybindings incorrect - first parameter must model , second parameter dom element. update code this:

ko.applybindings(new listeditorviewmodel(), document.body); 

or omit second parameter, because binding document anyway:

ko.applybindings(new listeditorviewmodel()); 

Comments

Popular posts from this blog

node.js - How to mock a third-party api calls in the backend -

node.js - Why do I get "SOCKS connection failed. Connection not allowed by ruleset" for some .onion sites? -

matlab - 0-by-1 sym - What do I need to change in order to get proper symbolic results? -