0

Background:

When the equivalent of javascript blur happens, I want to be able to edit the selectedOptions bound to a select list through knockout. For instance, select a specific element from a list, or clear the selection.

I found this topic which suggests two methods of implementing the "blur" part.

I would prefer to use the solution offered by Chris Pratt, as the system involves a lot of generated code, and it is much simpler if I don't have to change the knockout portion of it. All of my attempts so far have been using Chris Pratt's solution.

In my javascript, I am getting a handle on the relevant DOM elements with no problems. However, I am having difficulties getting a handle on the selectedOptions koobservablearray which is bound to the select. When I call ko.dataFor(DOMobject), it seems to return functions which return regular javascript arrays which are copies of my koobservablearrays, meaning that I can't edit them in order to change which option is selected.

Question:

So, is it possible to achieve what I am trying to do from "outside" of knockout, using methods like ko.dataFor or ko.contextFor? How are these methods intended to work? What are they good for?

Thanks!

Community
  • 1
  • 1
cobrabb
  • 141
  • 2
  • 10
  • 1
    When you say it "seems to return functions which return regular javascript arrays" -- that's what observable arrays are. – Ismail Badawi Jun 11 '14 at 22:58
  • @IsmailBadawi: does that mean that I can apply methods on the objects that belong to KoObservableArrays? For instance, is: `a = ko.dataFor(DOMobj); a.prop.removeAll;` Valid? – cobrabb Jun 12 '14 at 00:12
  • 1
    I'm saying `dataFor` seems to be returning an observable array in this case. Instead of asking whether something will work, you could just try it. – Ismail Badawi Jun 12 '14 at 01:04

0 Answers0