Solved

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

Posted on 2014-01-22
3
2,081 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

707 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

17 Experts available now in Live!

Get 1:1 Help Now