Solved

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

Posted on 2014-01-22
3
2,259 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 43

Expert Comment

by:Rob
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 43

Accepted Solution

by:
Rob 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
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…

719 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