Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

867 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

25 Experts available now in Live!

Get 1:1 Help Now