Solved

How to edit hierarchy to add new child values using JSON files

Posted on 2014-02-16
2
624 Views
Last Modified: 2014-02-18
I have two JSON files, Parent and Child.

How do I databind these for hierarchical editing using Knockout.JS / XEditable
in a HTML5 page.

eg edit Child and Add related records

Please provide samples and Code if possible
Thankyou
T1-Parent.JSON.txt
T2-Child.JSON.txt
0
Comment
Question by:XGIS
2 Comments
 
LVL 43

Accepted Solution

by:
Rob earned 500 total points
ID: 39865950
You can do this with pure JavaScript.

http://jsbin.com/bohug/1/edit

Why the need for knockout? Is the data tired to the ui ? ?

var mychildren = [{'CID':'1','CIDName':'Parent 1','PID':'1'},{'CID':'2','CIDName':'Parent 2','PID':'2'},{'CID':'3','CIDName':'Parent 3','PID':'3'},{'CID':'4','CIDName':'Parent 1','PID':'1'},{'CID':'5','CIDName':'Parent 1','PID':'1'},{'CID':'6','CIDName':'Parent 2','PID':'2'},{'CID':'7','CIDName':'Parent 3','PID':'3'}];
var myparents = [{'PID':'1','PIDName':'Parent 1'},{'PID':'2','PIDName':'Parent 2'},{'PID':'3','PIDName':'Parent 3'}];

for (var chd in mychildren) {
    for (var prt in myparents) {
        if (mychildren[chd].PID == myparents[prt].PID) {
            mychildren[chd].parent = myparents[prt];
        }
    }
}

console.log(mychildren);

Open in new window

0
 
LVL 7

Author Closing Comment

by:XGIS
ID: 39869441
Hello Rob.... thankyou for that clarification.... no it would be me that is 'tired'...  for not realising it...  and I am also  re'tiring' conventional sql but it is definitely not tied to the page, only to the controls it is servicing at the time and most likely provided in a JSON file that is being appended with child records and synchronised between users during a session.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question