dojo how to get all tree node of specific type? - dojo

I wrote the following code to create a dojo tree.
store = new dojo.data.ItemFileWriteStore({url: link});
treeModel = new dijit.tree.TreeStoreModel({
store: store,
query: {
"type": "ROOT"
},
rootId: "newRoot",
childrenAttrs: ["children"]
});
tree= new dijit.Tree({model: treeModel},"treeOne");
Following is my JSON file structure :
{
identifier: "id",
label: "name",
items: [
{id: "ROOT",name: "Change Windows",type: "ROOT"},
]}
I want to get all the nodes (basically their 'id' part)of specific 'type',lets say type= "ROOT". Is there anyway to get all those node? I thought of doing this using tree._itemNodeMap, but don't know any way to iterate through this whole item map,because it need a id as a input to return any specific node.

If you're talking about obtaining the data items programatically, you can get them straight from the store using fetch.
Sample JSON for ItemFile*Store:
{
"identifier": "id",
"label": "name",
"items": [{
"id": "ROOT",
"name": "Root",
"type": "ROOT",
"children": [{
"id": "P1",
"name": "StackExchange",
"type": "website",
"children": [{
"id": "C1",
"name": "StackOverflow",
"type": "website"
},
{
"id": "C2",
"name": "ServerFault",
"type": "website"
}]
},
{
"id": "P2",
"name": "Sandwich",
"type": "food",
"children": [{
"id": "C3",
"name": "Ham",
"type": "food"
},
{
"id": "C4",
"name": "Cheese",
"type": "food"
}]
},
{
"id": "P3",
"name": "Potluck",
"type": "mixed",
"children": [{
"id": "C5",
"name": "Google",
"type": "website"
},
{
"id": "C6",
"name": "Banana",
"type": "food"
}]
}]
}]
}
Sample code:
dojo.require('dojo.data.ItemFileReadStore');
dojo.ready(function() {
var store = new dojo.data.ItemFileReadStore({
url: 'so-data.json'
});
store.fetch({
query: {
type: 'food'
},
queryOptions: {
deep: true
},
onItem: function(item) {
console.log(store.getLabel(item));
}
});
});
This will log Sandwich, Ham, Cheese, and Banana.

Related

Ramda in angular to get to nested path

I am new to Ramda and have the follwing problem...I have a json file as follows
{
"name": "Alarms",
"props": {
"filterPropertyName": {
"value": "CompositeDataTypeName"
},
"children": {
"collection": [{
"name": "Adjustment Proximity Switch Failure Alarm",
"parent": {
"propName": "Children",
"propType": "c",
........
I used
notificationKeys = r.pipe(r.view(r.lensPath([entitiesSelectorName, 'alarms'])), r.keys);
to get "name": "Adjustment Proximity Switch Failure Alarm",
If sometimes the json files come as follows,
{
"name": "Alarms",
"props": {
"filterPropertyName": {
"value": "CompositeDataTypeName"
},
"children": {
"collection": [{
"name": "Alarm Bits Dint01",
"parent": {
"propName": "Children",
"propType": "c",
"hidden": true
},
"props": {
"bits": {
"collection": [{
"name": "BELT SLIP ALARM",
"parent": {
"propName": "Bits",
"propType": "c",
"hidden": false
},
"type.........
The notificationKeys gets me to "name": "Alarm Bits Dint01"....how can I get to "name": "BELT SLIP ALARM",
Any help will be greatly appreciated.

DocumentDB filter documents on multiple items in a child array

I have a Cosmos DB database with documents that have the following form:
{
"Id": "1",
"Price": 200,
"Properties": [
{
"Name": "Name1",
"Type": "Type1",
},
{
"Name": "Name2",
"Type": "Type2",
}
]
},
{
"Id": "2",
"Price": 500,
"Properties": [
{
"Name": "Name1",
"Type": "Type1",
},
{
"Name": "Name2",
"Type": "Type3",
}
]
},
{
"Id": "3",
"Price": 400,
"Properties": [
{
"Name": "Name1",
"Type": "Type2",
}
]
}
I would like to create a query that returns documents that satisfy multiple properties. E.g. I would like to retrieve the documents that have both properties of Type1 and Type2. The result should give me only the document with Id = 1.
SELECT c.Id
FROM c
WHERE ARRAY_CONTAINS(c.Properties, {'Type': 'Type1' }, true)
AND ARRAY_CONTAINS(c.Properties, {'Type': 'Type2' }, true)

How to expand tree node without ajax request?

I am using Extjs tree, i got problem with click on nested node ajax request to server, i know this kind of lazy load but my tree is not big, around 35 items so i want request to server time only to collect all tree node and items.
Any idea?
View:
Ext.define('CRM.view.role.RoleTree' ,{
extend: 'Ext.tree.Panel',
alias: 'widget.roleTreeList',
id:'tree-role-panel',
split: false,
autoScroll: true,
lines: true,
singleExpand: false,
store: 'RoleList'
})
Store:
Ext.define('CRM.store.RoleList', {
extend: 'Ext.data.TreeStore',
storeId: 'RoleTreeStoreId',
//model: 'CRM.model.RoleList',
autoLoad: false,
proxy: {
type : 'ajax',
url : 'index.php/role/getRoleList',
async : false,
reader: {
type : 'json',
method : 'POST'
}
},
root:{
expanded:true,
text:"Organization",
leaf:'false',
id : '/',
}
})
Json return:
{
"text": "Organization",
"id": "role-1",
"children": [
{
"text": "Admin",
"id": "role-12",
"expanded": "true",
"children": [
{
"text": "MSD",
"id": "role-23",
"children": [
{
"text": "Customer Care Manager",
"id": "role-4",
"children": [
{
"text": "Customer Care Adviser",
"id": "role-5"
}
]
},
{
"text": "Solution Adviser",
"id": "role-7"
},
{
"text": "Sales Manager",
"id": "role-31",
"children": [
{
"text": "Solution Sales",
"id": "role-6"
},
{
"text": "Teritory 01 - Safy",
"id": "role-9",
"children": [
{
"text": "Sales Person 01",
"id": "role-10"
},
{
"text": "Sales Trainee 01",
"id": "role-26"
}
]
},
{
"text": "Teritory 3 - Sambo",
"id": "role-11",
"children": [
{
"text": "Sales Person 3",
"id": "role-13"
}
]
},
{
"text": "Teritory 4 - Narong",
"id": "role-14",
"children": [
{
"text": "Sales Team 4",
"id": "role-15",
"children": [
{
"text": "Sales Person 4",
"id": "role-25"
}
]
}
]
},
{
"text": "branch shv",
"id": "role-16",
"children": [
{
"text": "sales shv",
"id": "role-19"
}
]
},
{
"text": "branch btb",
"id": "role-17",
"children": [
{
"text": "sales btb",
"id": "role-20"
}
]
},
{
"text": "branch srp",
"id": "role-18",
"children": [
{
"text": "sales srp",
"id": "role-21",
"children": [
{
"text": "sales person srp",
"id": "role-28"
}
]
}
]
},
{
"text": "Retention Program",
"id": "role-22",
"children": [
{
"text": "Retention Program Analysist",
"id": "role-24"
}
]
},
{
"text": "Sales Trainee",
"id": "role-27"
},
{
"text": "Enterprise Sales Engineer",
"id": "role-29"
},
{
"text": "Meas Test",
"id": "role-30"
},
{
"text": "Teritory 02 - Kol",
"id": "role-32",
"children": [
{
"text": "Sales Person 02",
"id": "role-8"
}
]
}
]
}
]
},
{
"text": "CTO",
"id": "role-35",
"children": [
{
"text": "Support Manager",
"id": "role-2",
"children": [
{
"text": "Technical Support Adviser",
"id": "role-3"
}
]
},
{
"text": "IT BIlling Product Manager",
"id": "role-33",
"children": [
{
"text": "IT Staff",
"id": "role-34"
}
]
}
]
},
{
"text": "Business Consultant",
"id": "role-36"
}
]
}
]
}
You can still use asynchronous call, but only once. To make sure only one call is made, return all children in first call. Extjs will load all children provided.
I found my mistake with JSON, i should add property "leaf = true/false" according has child or hasn't.

dojo.data.ItemFileWriteStore: Invalid item argument in dijit.tree

While working with dojo toolkit and the djit.tree widget, I received the the following error:
dojo.data.ItemFileWriteStore: Invalid item argument
in my javascript function which loads data in json format from my php server and displays it in a dijit.tree using a ItemFileWriteStore and a ForestStoreModel. My json data is the following:
{
"identifier": "id",
"label": "name",
"items": [{
"type": "parent",
"name": "Adresse des Finanzamts",
"id": "1020right00",
"children": [{
"type": "Leaf",
"name": "Relationship type: 1:1",
"id": "Adresse des Finanzamts1:1"
}, {
"type": "parent",
"name": "Left",
"id": "Adresse des Finanzamts010",
"children": [{
"type": "Leaf",
"name": "Table name: Finanzamtdaten",
"id": "1014left23432"
}, {
"type": "Leaf",
"name": "Field name: fkFinanzamtAdresse:INTEGER",
"id": "1018lef423t"
}]
}, {
"type": "parent",
"name": "Right",
"id": "Adresse des Finanzamts111",
"children": [{
"type": "Leaf",
"name": "Table name: Adresse",
"id": "105right234"
}, {
"type": "Leaf",
"name": "Field name: adresseId:INTEGER",
"id": "106right2223"
}]
}]
}, {
"type": "parent",
"name": "Adresse des Mitarbeiters",
"id": "1013right00",
"children": [{
"type": "Leaf",
"name": "Relationship type: 1:1",
"id": "Adresse des Mitarbeiters1:1"
}, {
"type": "parent",
"name": "Left",
"id": "Adresse des Mitarbeiters010",
"children": [{
"type": "Leaf",
"name": "Table name: Mitarbeiter",
"id": "100left23432"
}, {
"type": "Leaf",
"name": "Field name: fkAdresse:INTEGER",
"id": "1012lef423t"
}]
}, {
"type": "parent",
"name": "Right",
"id": "Adresse des Mitarbeiters111",
"children": [{
"type": "Leaf",
"name": "Table name: Adresse",
"id": "105right234"
}, {
"type": "Leaf",
"name": "Field name: adresseId:INTEGER",
"id": "106right2223"
}]
}]
}]
}
The code is formatted on server side using json_encode().
var treeObject = dijit.byId("relationStructure");
treeObject.model.store.clearOnClose = true;
treeObject.model.store.close();
var newStore = new dojo.data.ItemFileWriteStore({
data: data
});
treeObject.model.store = newStore;
treeObject.model.query = {"type": "parent"};
treeObject.rootId = "root";
treeObject.rootLabel = "Table content";
treeObject.childrenAttrs = ["children"];
treeObject.showRoot = false;
treeObject.refreshModel();
Now json data:
{"identifier":"id","label":"name","items":[{"type":"parent","name":"Finanzamtdaten des Mitarbeiters","id":"1022right000","children":[{"type":"Leaf","name":"Relationship type: 1:1","id":"Finanzamtdaten des Mitarbeiters1:1"},{"type":"parent","name":"Left","id":"Finanzamtdaten des Mitarbeiters0100","children":[{"type":"Leaf","name":"Table name: Mitarbeiter","id":"100left234320"},{"type":"Leaf","name":"Field name: fkFinanzamtdaten:INTEGER","id":"1019lef423t0"}]},{"type":"parent","name":"Right","id":"Finanzamtdaten des Mitarbeiters1110","children":[{"type":"Leaf","name":"Table name: Finanzamtdaten","id":"1014right2340"},{"type":"Leaf","name":"Field name: finanzamtdatenId:INTEGER","id":"1015right22230"}]}]},{"type":"parent","name":"Adresse des Mitarbeiters","id":"1013right001","children":[{"type":"Leaf","name":"Relationship type: 1:1","id":"Adresse des Mitarbeiters1:1"},{"type":"parent","name":"Left","id":"Adresse des Mitarbeiters0101","children":[{"type":"Leaf","name":"Table name: Mitarbeiter","id":"100left234321"},{"type":"Leaf","name":"Field name: fkAdresse:INTEGER","id":"1012lef423t1"}]},{"type":"parent","name":"Right","id":"Adresse des Mitarbeiters1111","children":[{"type":"Leaf","name":"Table name: Adresse","id":"105right2341"},{"type":"Leaf","name":"Field name: adresseId:INTEGER","id":"106right22231"}]}]}]}
You have an id collision with your data. There are two items with the same id of 105right234 and 106right2223.
"dojo.data.ItemFileWriteStore: The json data provided by the creation arguments
is malformed. Items within the list have identifier: [id].
Value collided: [105right234]"
If you want the same item to appear twice in the structure, then you need to look at how the _reference structure is used.
http://dojotoolkit.org/reference-guide/1.8/dojo/data/ItemFileReadStore.html#input-data-format
Your second set of data loads fine into the store.
The following code is not good practice for Dojo widgets.
treeObject.model.store = newStore;
treeObject.model.query = {"type": "parent"};
treeObject.rootId = "root";
treeObject.rootLabel = "Table content";
treeObject.childrenAttrs = ["children"];
treeObject.showRoot = false;
Dojo uses the convention of myWidget.set('model', new model); This allows for custom setter logic. See this link for more.
http://dojotoolkit.org/reference-guide/1.8/quickstart/writingWidgets.html#custom-setters-getters
I created another fiddle that uses your data and creates a tree.
http://jsfiddle.net/cswing/5Yjx9/

Extracting values from a JSON string

I want to retrieve the different tag values in an NSString.
NSString *test =
{
"data": [
{
"id": "100002319144563_125257217561582",
"from": {
"name": "Umair Ahmed",
"id": "100002319144563"
},
"message": "Hello Umair Here",
"actions": [
{
"name": "Comment",
"link": "http://www.facebook.com/100002319144563/posts/125257217561582"
},
{
"name": "Like",
"link": "http://www.facebook.com/100002319144563/posts/125257217561582"
}
],
"privacy": {
"description": "Everyone",
"value": "EVERYONE"
},
"type": "status",
"application": {
"name": "iPhone",
"id": "213257025359930"
},
"created_time": "2011-07-08T11:59:15+0000",
"updated_time": "2011-07-08T11:59:15+0000"
},
{
"id": "100002319144563_125251050895532",
"from": {
"name": "Umair Ahmed",
"id": "100002319144563"
},
"message": "Hello testing testing",
"actions": [
{
"name": "Comment",
"link": "http://www.facebook.com/100002319144563/posts/125251050895532"
},
{
"name": "Like",
"link": "http://www.facebook.com/100002319144563/posts/125251050895532"
}
]
}
]
}
How can I retrieve the name and message tag values into an array or dictionary?
It looks like a JSON string, so just use one of JSON libraries, like TouchJSON or JSONKit and you can easily extract the data from the structures they will provide you.