I am very very new to knockoutjs - having worked through the tutorials and I have made a nice start. I have application which seems well suited to KO. In that I need to populate a table with data from JSON. This data is nested, and can be nested at any depth, but my API will only ever return data two levels deep.
E.g.
- Node 1
- Node A
- Node B
I've managed to get the data to load into my table, lovely. I've taken this a step further and have supported nesting. I have a requirement so that if a Node has children, it can be injected beneath the Node into the table.
An example of this would be...
- Node 1 (HasChildren)
- Node A
- Node B (HasChildren)
As Node B 'HasChildren', I would like to allow the loading of it's children into the table, beneath Node B. In this event, I would be able to query my API, and it would return the children for Node B
- Node 1
- Node A
- Node B
- Node B1
- Node B2
I've got something roughly working, but it only works on a level 1 node. Once it get's to level2, can't seem to find my method (addChild). I can't work out why it cannot find the method, as it is in my ViewModel.
The post below, goes a long way to fixing this part of the problem.
Help!
I've pasted the code here... (if you scroll to the right on the table, you can click open, to see, what's happening!)
http://jsfiddle.net/8k6pj/1/ - Original Version (18th April 2012)
http://jsfiddle.net/8k6pj/6/ - Latest Version
Many thanks in advance!
Laurence
p.s Have further updated my code, so although I'm a bit stuck on the above, have started looking into implementing how the code will postback so we can save.
It looks like the postback is working, however it does not post back the changed values, the original values are posted back. Think this is because I need to use an ObservableArray, exploring that now.