Solved

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

Posted on 2014-02-16
2
617 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 42

Accepted Solution

by:
Rob Jurd, EE MVE 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
angularls and plnkr 14 18
Hidden Field Value 10 34
Unable  to create new object 9 24
Bootstrap 3 icons 3 11
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now