Iterative data store in extjs - extjs4.1

I want to create hierarchical tabs ( they could be up to n level) using ext-js 4.1. I am trying to create a store as below, for the tab hierarchy. so I can use a generic method to create tabs. How can i iterate through this store structure to create hierarchical tabs?
Hope the structure below is readable :-) showing each level clearly and the depth for the tabs.
"toptab1": [{
"id" : 1000
"name" : "coo",
"child": [{
"id": 1 ,
"name": "foo" ,
"child": [{
"id" : 11 ,
"name": "roo" ,
"child": [{
"id" : 111,
"name" : "hoo"
},
{
"id: 112,
"name": "poo"
}]
},
{
"id" : 12 ,
"name" : "too"
}]
},
{
"id" : 2,
"name" : "woo",
"child" :[{
"id": 21,
"name" : "soo"
"child" : [{
"id" : 211,
"name" : "boo"
}]
},
{
"id" : 22,
"name" : "doo"
}]
},
{
"id" : 3,
"name": "zoo"
}];

I would create a model to store the information about your tabs.
Then use a TreeStore to store them in the correct hierarchy.
Then you can do something like.
var topLevel = this.getTabStore().getRootNode();
topLevel.cascadeBy(function(tab) {
//Do what you want with each tab here.
});
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.TreeStore-method-getRootNode
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.NodeInterface-method-cascadeBy

Related

How could I create indexes in postgres using jsonb?

I have a table in my database as follows
my_table:jsonb
[ {
"name" : "world map",
"type" : "activated",
"map" : [ {
"displayOrder" : 0,
"value" : 123
}, {
"displayOrder" : 1,
"value" : 456
}, {
"displayOrder" : 2,
"value" : 789
} ]
}, {
"name" : "regional map",
"type" : "disabled"
} ]
I would like to create indices for the name, type and displayOrder fields, which would be the best way?

Remove Subdocument items with $pull

I'm trying to remove items from subdocuments using ExpressJS and Mongoose but it is only removing the first items, not the sub items.
So I want to remove "subitem 2" in the messages Array
This is the structure:
{
"_id" : ObjectId("5c4ee94b30ebd71cbed89a35"),
"title" : "Test",
"subitem" : [
{
"_id" : ObjectId("5c4ee95630ebd71cbed89a36"),
"title" : "Item 1",
"messages" : [
{
"_id" : ObjectId("5c4ee95f30ebd71cbed89a37"),
"type" : "single_article",
"date" : "Jan 28, 2019",
"title" : "subitem 1",
"text" : ""
}
]
},
{
"_id" : ObjectId("5c4ee96830ebd71cbed89a38"),
"title" : "item 2",
"messages" : [
{
"_id" : ObjectId("5c4ee96e30ebd71cbed89a39"),
"type" : "single_article",
"date" : "Jan 28, 2019",
"title" : "subitem 2",
"text" : ""
}
]
}
],
"__v" : 0
}
And this is the $pull method:
getController.deleteRec = function(req,res,collection){
var id = req.params.id;
console.log(id);
collection.updateOne({'subitem.messages._id': id}, {$pull: {'subitem.0.messages': {"_id": id}}}).
then(function(result){
console.log(result);
});
};
Now I know why it is only deleting the first item because I have "subitem.0.messages". How can I loop over this, so it can delete all items?
You can use $ as a wildcard index, removing all elements in the array matching your query like this:
{$pull: {'subitem.$.messages': {"_id": id}}}
if you want to remove multiple documents:
{$pull: {'subitem.$.messages': {"_id": {$in : [id, id2, id3...]}}}}

softlayer api: How to order Public Secondary IP Addresses when I ordering?

I want to order Public Secondary IP Addresses when I ordering. And How to submit these order infomation by softlayer api ?
To submit the order information described above, you need to fill the parameter "itemCategoryQuestionAnswers" during the order, that parameter can be found in datatypes like Container_Product_Order_Virtual_Guest and Container_Product_Order_Hardware_Server
Below is an example in JSON for REST:
"itemCategoryQuestionAnswers":[
{
"answer": "2",
"categoryId": 14,
"questionId": 14
},
{
"answer": "4",
"categoryId": 14,
"questionId": 15
}
]
The example above belongs to the first two questions in the form. As you can see, it is necessary to know the id of categoryId and questionId parameters. Follow the steps below.
CategoryID
As greyhoundforty comment you, the link SoftLayer API: Ordering Subnet
is a good starting point. On that page mcruz shows how to execute the method Product_Item_Category::getSubnetCategories. The method returns some thing like this:
{
"categoryCode": "global_ipv6",
"id": 331,
"name": "Global IPv6",
"quantityLimit": 0
},
{
"categoryCode": "sec_ip_addresses",
"id": 14,
"name": "Public Secondary IP Addresses",
"quantityLimit": 0
},
On this case the categoryId is 14 for category "Public Secondary IP Addresses".
QuestionID
To get all questions related to the category "sec_ip_addresses" you can use the method Product_Item_Category::getQuestions or Product_Item_Category::getQuestionReferences. On this case I'll show you how execute getQuestionReferences method:
https://[username]:[apikey]#api.softlayer.com/rest/v3/SoftLayer_Product_Item_Category/14/getQuestionReferences?objectMask=[question]
Method: GET
It should returns something like this:
{
"id": 61,
"questionId": 14,
"required": true,
"question": {
"description": "The number of IP addresses expected to be used within the next 30 days.",
"id": 14
}
},
{
"id": 62,
"questionId": 15,
"required": true,
"question": {
"description": "The number of IP addresses expected to be used within the next 12 months.",
"id": 15
}
},
Now you can know the questionId of each question in the form.
Order Virtual Guest with a Secondary Public Ip Address
Below is an example in REST to order a virtual guest with a secondary ip address and two first questions in the form.
Note: Don't forget change [username], [apikey], prices, and other ids with your own data
https://[username]:[apikey]#api.softlayer.com/rest/v3/SoftLayer_Product_Order/verifyOrder
Method: POST
Body JSON:
{
"parameters":[
{
"complexType": "SoftLayer_Container_Product_Order_Virtual_Guest",
"packageId": 46,
"location": "AMSTERDAM",
"quantity": 1,
"prices":[
{"id":14640},
{"id":11644},
{"id":9205},
{"id":22272},
{"id":52231},
{"id":21},
{"id":2202},
{"id":13945},
{"id":55},
{"id":57},
{"id":58},
{"id":420},
{"id":418},
{"id":22}
],
"virtualGuests":[
{
"hostname": "test",
"domain": "example.com"
}
],
"itemCategoryQuestionAnswers":[
{
"answer": "2",
"categoryId": 14,
"questionId": 14
},
{
"answer": "4",
"categoryId": 14,
"questionId": 15
}
]
}
]
}
About your REST structure
I don't know what REST client you are using, but I was able to reproduce your issue in a RESTclient from firefox, in other REST clients like Insomnia I'm just getting errors.
Basically, you are getting empty response because your JSON structure have some mistakes. First, all data in body needs to be into "parameters" object, please review the example above. Second, value of "sshKeyIds" needs to be into double quotes because it is an string. Finally, I recommend you put all objects and string values into double quotation mark due to it is the JSON standard format, you can verify this information in jQuery.parseJSON single quote vs double quote and http://www.json.org/.
Important: Before to use placeOrder method I recommend you to execute verifyOrder first. When, you are ready to order just change verifyOrder by placeOrder in the URL request.
I modified your request as following
https://[username]:[apikey]#api.softlayer.com/rest/v3/SoftLayer_Product_Order/verifyOrder
Method: POST
Body in JSON format:
{
"parameters":[
{
"complexType" : "SoftLayer_Container_Product_Order_Virtual_Guest",
"location" : "449604",
"packageId" : 46,
"quantity" : 1,
"useHourlyPricing" : true,
"virtualGuests" : [
{
"domain" : "aaa.com",
"hostname" : "sshkey_07"
}
],
"sshKeys" : [
{ "sshKeyIds" : ["620913L"] }
],
"prices" : [
{"id" : 1644 },
{"id" : 2202 },
{"id" : 2259 },
{"id" : 273 },
{"id" : 1640 },
{"id" : 17442},
{"id" : 905 },
{"id" : 21 },
{"id" : 57 },
{"id" : 55 },
{"id" : 58 },
{"id" : 420 },
{"id" : 418 },
{"id" : 22 },
{"id" : 1800 }
],
"itemCategoryQuestionAnswers" : [{
"answer" : "4",
"questionId" : 14,
"categoryCode" : "sec_ip_addresses",
"categoryId" : 14
}, {
"answer" : "4",
"questionId" : 15,
"categoryCode" : "sec_ip_addresses",
"categoryId" : 14
}, {
"answer" : "aaaa",
"questionId" : 16,
"categoryCode" : "sec_ip_addresses",
"categoryId" : 14
}, {
"answer" : "allesa",
"questionId" : 9,
"categoryCode" : "sec_ip_addresses",
"categoryId" : 14
}, {
"answer" : "product manager",
"questionId" : 10,
"categoryCode" : "sec_ip_addresses",
"categoryId" : 14
}, {
"answer" : "xxx#mail.com",
"questionId" : 11,
"categoryCode" : "sec_ip_addresses",
"categoryId" : 14
}, {
"answer" : "xxxxxxxxx",
"questionId" : 12,
"categoryCode" : "sec_ip_addresses",
"categoryId" : 14
}, {
"answer" : "1",
"questionId" : 13,
"categoryCode" : "sec_ip_addresses",
"categoryId" : 14
}
]
}
]
}
Let me know if you have any doubt or need further assistance.

dojo How Tree insert data to children?

hi i want to insert data to children to Tree.but I want to put the data.for example i want to update children[0] information.Rather than creating a new one I'd like to update the existing data.
my Tree.json
{
"name": "SCATTER/BUBBLE CHART",
"id": "SCATTERBUBBLE",
"children": [
{
"name": "Series",
"id": "SERIES",
"children": [
{
"name" : "Data:X",
"id" : "DX"
},
{
"name" : "Data:Y",
"id" : "DY"
}
]
},
{
"name": "XAxis",
"id": "X"
},
{
"name": "YAxis",
"id": "Y"
}
]
}
if i click button,i want to result
{
"name": "SCATTER/BUBBLE CHART",
"id": "SCATTERBUBBLE",
"children": [
{
"name": "Series",
"id": "SERIES",
"children": [
{
"name" : "Data:X",
"id" : "DX"
},
{
"name" : "Data:Y",
"id" : "DY"
},
{
"name" : "Data:Z",
"id" : "DZ"
}
]
},
{
"name": "XAxis",
"id": "X"
},
{
"name": "YAxis",
"id": "Y"
},
{
"name": "ZAxis",
"id": "Z"
}
]
}
i don't know update children tree ask for advice
Use node.item to get the store item object which has created the node. I hope you have the node object. For instance if you want to get the root node of your tree :-
var rootNode = dijit.byId("treeID").attr("rootNode");
After you get the node's item object you may update any of its attributes and your store will be modified. Your store should also extend "dojo/store/Observable", so that your tree gets updated with the changes to store.

transform json to work with ember-data

When visiting my test api it returns a json in the following format to my ember application:
{
{ "1" : {
"id" : "1",
"name" : "test1",
"amount" : "12,90"
}
},
{ "2" : {
"id" : "2",
"name" : "test2",
"amount" : "9,30"
}
},
}
My Model for the data is looks like this:
var budget = DS.Model.extend({
amount: DS.attr('string'),
name: DS.attr('string')
});
export default budget;
With the given JSON my hbs template render nothing as no model was set by ember data...
The format i would expect looks like the following example:
{
[{
"id" : "1",
"name" : "test1",
"amount" : "12,90"
},
{
"id" : "2",
"name" : "test2",
"amount" : "9,30"
}]
}
Is there a possibility to transform the upper json to the json i expected? I am using the Ember App Kit for my application. As API i want to use SLIM Php Framework with NotORM.
EmberData expects the JSON format returned by your API to be in this format for all budgets:
{
"budgets":
[{
"id" : "1",
"name" : "test1",
"amount" : "12,90"
},
{
"id" : "2",
"name" : "test2",
"amount" : "9,30"
}]
}
And for a single budget, it expects:
{
"budget": { "id": 2, "name": "test", "amount": "9,30" }
}
If you want to override this by creating your own extractSingle and extract methods in the BudgetSerializer. You can find more info here
App.BudgetSerializer = DS.RESTSerializer.extend({
// First, restructure the top-level so it's organized by type
extractSingle: function(store, type, payload, id, requestType) {
// do your transformation
return this._super(store, type, payload, id, requestType);
}
});