In a (webforms) page I have a button that opens a jqueryui dialogue which is loaded dynamically.
The problem is that I want this dialogue to be master of its own knockout view model but the view model is already set in the main page.
I suppose it is not possible to add new properties to the view model after ko.applyBindings
is called.
Instead I should be looking into another design. But which?
- Applying bindings to different parts of the DOM would require me to some big redesigns I hope to avoid right now.
- Having all the dialoge bindings as a list of key-values is possible but not very elegant IMHO. The main page would then only have to add a
vm.dialogueKeyvalueCollection
. - My present, possible, solution is to have the main form add the dialogue's properties
vm.dialogue.userName() vm.dialogue.searchResult()
but then my html controls won't bind as they are created afterapplyBindings
is called. The present solution for this is to callApplyBindings
again like so:ko.applyBindings(vm, $('#dialog-form')[0]);
for the added HTML. I was in the belief (and still somewhat am) that to callapplyBindings
for different DOM elements one must not be nested inside another. Binding to dynamic HTML is commented here and jsfiddled here. - ?