Check out this fiddler link With the working Code: KO Example Code
The Idea is to populate them with data then be able to move them back and forth between the two lists.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The populating of the selects works fine for me once I added a resource in jsFiddle to the knockout js file. I used http://knockoutjs.com/js/knockout-1.2.0.js
Ok, I’ve edited my answer and removed most of it once I realised that I’d misunderstood @hyperslug’s reply, and then went and produced pretty much exactly the same code! @hyperslug’s answer, was slightly better than mine as I hadn’t realised that removeAll returns an array of removed items.
In addition to @Hyperslug’s answer, you also have a problem with the enabled state of the buttons. On page load this is solved by
instead of
The latter creates an observable array of length 1 instead of 0.
To get the button enabled status to change after all items have been unchecked, you do seem to need to clear down availHighlight or selectHighlight. removeAll() to the rescue again.
this.availHighlight.removeAll()
or
this.selectHighlight.removeAll()
In answer to why @hyperslug’s $.each() code didn’t work, this is because inside a jQuery each() anonymous function, ‘this’ refers to the item in the collection, not the viewModel instance.
Hope this helps