I don't think it is possible to use a foreach bound to an observableArray in a jQuery UI dialog that is bound to the viewmodel - other bindings, e.g. text, that are bound to observable seem to work fine.
This broken sample uses a dialog bound to the viewmodel which I based on a sample found here (I think).
This sample accomplishes what I want. The dialog, however, is not bound to the viewmodel, instead I wire up a click handler to a button to launch the dialog (taken from this article).
Is this a bug, or am I doing it wrong?
This is a MVC3 project, using jQuery-1.7.2, jQuery-ui-1.8.20.js and knockout-2.1.0.
(This is taken from my SO question)
@andygjp Here is your broken sample with a minor modification to call the .dialog() in a setTimeout: http://jsfiddle.net/rniemeyer/YuV55/5/. The jQuery UI dialog functionality moves the element to the bottom of the page, so it can mess up the bindings as the initial pass of ko.applyBindings hits it for a second time.
Here is another sample that calls ko.applyBindings specific to a container element (without the setTimeout): http://jsfiddle.net/rniemeyer/YuV55/6/. This means that ko.applyBindings won't hit the moved dialog the second time, as it will be outside of the container element.
Sorry, I don't have time to add any more details. Hope this helps.
#466 presents some ideas on preventing Knockout from trying to bind an element twice. Closing this as it's the same issue.
Thanks for that, I've marked your response as the answer.
I'll just close this issue.