[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2014-01-22
3
Medium Priority
?
2,400 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
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…
Suggested Courses

649 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