Dynamic control creation using Knockout.js -


i developing application reads xml file , xml file has info type of controls rendered on browser textbox,combo etc. planning implement same using knockout.js. best possible view model design implement same.

consider xml file as:

<controls> <parentelement> <attr id="1" visibilty="t" type="combobox"></attr> <attr id="2" visibilty="n" type="combobox"></attr> </parentelement> <childelement dependson="1"> <attr id="3" visibilty="t" type="textbox" value="abc"></attr> <attr id="4" visibilty="t" type="combobox" value="xyz"></attr> </childelement> <childelement dependson="2"> <attr id="5" visibilty="t" type="textbox" value="def"></attr> <attr id="6" visibilty="t" type="combobox" value="pqr"></attr> </childelement> </controls> 

expected output should parent element controls should displayed first , if selected id="1" childelement dependson id="1" should displayed.

any on highly appreciated.

thanks, sajesh nambiar

some kind of factory pattern?

this utlizes lib ive written not vanilla ko

http://jsfiddle.net/rduzh/

this factory part, rest ko magic lib

this.editors = ko.utils.arraymap(data, function(item) {     return new myapp.editors[item.type + "editorviewmodel"](item); }); 

my lib: https://github.com/andersmalmgren/knockout.bindingconventions

install using nuget

install-package knockout.bindingconventions 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -