Solved

how to use dataFilter in JQuery(JsTree) to filter the json data?

Posted on 2014-01-22
3
2,139 Views
Last Modified: 2014-01-25
Hi,

I have this json data I need to filter/parse out data so it can be fed to the JsTree.
What I need from this json data is the content of the property2.

[
'property1':'abc',
'property2': [

{ 'text': 'john doe', 'age':'29', 'id':'123', 'uri': 'xxxxx'},
{ 'text': 'jane doe', 'age':'22', 'id':'122', 'uri': 'xxxxx'},
{ 'text': 'joe doe', 'age':'12', 'id':'121', 'uri': 'xxxxx'}
]
'property12':'bcc'
]

Open in new window


Need this section:
[

{ 'text': 'john doe', 'age':'29', 'id':'123', 'uri': 'xxxxx'},
{ 'text': 'jane doe', 'age':'22', 'id':'122', 'uri': 'xxxxx'},
{ 'text': 'joe doe', 'age':'12', 'id':'121', 'uri': 'xxxxx'}
]

Open in new window

0
Comment
Question by:dkim18
  • 2
3 Comments
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 39805233
You do it like this: http://jsbin.com/OfUdElA/2/edit?js,output

var myjson = {
  'property1':'abc',
  'property2': [
  { 'text': 'john doe', 'age':'29', 'id':'123', 'uri': 'xxxxx'},
  { 'text': 'jane doe', 'age':'22', 'id':'122', 'uri': 'xxxxx'},
  { 'text': 'joe doe', 'age':'12', 'id':'121', 'uri': 'xxxxx'}
  ],
    'property12':'bcc'
};

$(document).ready(function () { 
  $('#jstree2').jstree({ 'core' : {
    'data' : myjson.property2
  } });
});

Open in new window

0
 

Author Comment

by:dkim18
ID: 39806370
Gee, that was easy.
is this array or json object?
or did I mean samething here?

myjson.property2
0
 
LVL 42

Accepted Solution

by:
Rob Jurd, EE MVE earned 500 total points
ID: 39808124
JSON stands for "Javascript Object Notation" and is just a javascript object.  It's a term given to an object that has a particular format.  As for the jsTree they stipulate that "your JSON must look like [this]" to work with our plugin (which is just another javascript object)

In fact everything in javascript inherits from the javascript object.

eg

// an array
var myarray = [];
myarray['first'] = [1,2,3,4,5];
console.log(myarray.first); // can be written in dot notation like an object

So an array is an extension of an object with it's own specific methods and properties eg .length .indexOf() - however you can extend the object (scroll to "Create new methods")if you need to do more with it
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

776 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