[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
Suggested Courses
Course of the Month18 days, 20 hours left to enroll

834 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