Displaying the query using jquerybuilder - javascript

I used jQuery QueryBuilder (http://querybuilder.js.org/) to create the rules and generate JSON and store them in a database. Now, I need to do the reverse operation. This means,that the input will be in the form of a JSON which would get parsed and display the rules in the UI in the same format of QueryBuilder for modification/deletion. Can someone provide pointers/sample code on how to achieve this?

To achive this you have to use the *setRules * method --> see documentation here
var rules_json= {
condition: 'AND',
rules: [{
id: 'price',
operator: 'less',
value: 10.25
}, {
condition: 'OR',
rules: [{
id: 'category',
operator: 'equal',
value: 2
}, {
id: 'category',
operator: 'equal',
value: 1
}]
}]
};
$('#queryBuilder').queryBuilder('setRules', rules_json);

Related

how can i handle my json elements

Here is my json file
{
id: '81224112234234222223422229',
type: 'message',
message: 'vacation',
attachments: [
{
type: 'template',
elements: [
{
id: '123123123123123',
title: 'job',
text: 'job',
properties: {
code: 'IO002',
value: 'messenger/IO001,messenger2(IO)/IO002,messenger3(IO)/IO003'
}
},
{
id: '123123123123123',
title: 'Date',
text: 'date',
properties: {
code: '2017-11-09~2017-11-09',
value: '2017-11-09~2017-11-09'
}
},
{
id: '123123123123123',
title: 'Sequence',
text: 'sequence',
properties: {
code: '1',
value: '1process/1,2process/1,3process/1'
}
}
]
}
],
module: 'temp'
}
i am using react.js and i want to extract all properties
result
job code: I0002
job value:messenger/IO001,messenger2(IO)/IO002,messenger3(IO)/IO003
date code:2017-11-09~2017-11-09
date value:2017-11-09~2017-11-09
sequence code:1
sequence value:1process/1,2process/1,3process/1
i tried to execute like this
const job=elements.filter(x=>x.text==='job');
const date=elements.filter(x=>x.text==='date');
const sequence=elements.filter(x=>x.text==='sequence');
is it proper way to use filter or another way to extract data from json file?
i am new to react.js and es6,javascript.so i have no idea to display each property.
how can i solve my problem? pz give me a tip.i want to extract properties
You can use
var yourobject=JSON.parse(jsondata);
const job=yourobject.job;

Make a new object from an array of objects [duplicate]

This question already has answers here:
Create an object with dynamic property names [duplicate]
(2 answers)
Closed 6 years ago.
This is possibly a duplicate, but everywhere I search I can only seem to find people wanting to create an array of objects.
Basically I'm trying to achieve the opposite, pull certain values of an array of objects out into an object. It's twisting my head a little so any of you JS gurus out there if you could give me a hand it would be very very appreciated!
Basically I have an array of objects like this:
[
{ field: 'name', value: 'sam', isRequired: true },
{ field: 'email', value: 'sam#dummyemail.net', isRequired: true },
{ field: 'message', value: 'hey', isRequired: false },
]
They're split up this way because I go through the fields for validation.
After the validation phase I want to map the field and value properties to name value pairs within a new object e.g:
{
name: 'sam',
email: 'sam#dummyemail.net',
message: 'hey',
}
Like I said any help would be amazing! Cheers.
Array#map each object in the array into a new object with field as the key of a property, and value, well, the value of the property. Then combine the new objects array to object using the spread syntax and Object#assign:
const arr = [
{ field: 'name', value: 'sam', isRequired: true },
{ field: 'email', value: 'sam#dummyemail.net', isRequired: true },
{ field: 'message', value: 'hey', isRequired: false },
];
const result = Object.assign({}, ...arr.map(({ field, value }) => ({ [field]: value })));
console.log(result);
you could map array into object like this
var array = [
{ field: 'name', value: 'sam', isRequired: true },
{ field: 'email', value: 'sam#dummyemail.net', isRequired: true },
{ field: 'message', value: 'hey', isRequired: false },
];
var object = {};
array.forEach(x => {
object[x.field] = x.value;
});
console.log(object);

Extjs sorting store by alphanumeric field

I've got a bunch of records whose names are like "Itemtype #", and when they are outputted into a tree view, they're sorted incorrectly, like so:
Item 1
Item 10
Item 11
Item 12
Item 13
Item 2
Item 3
Item 4
My model fields are defined as follows, and I am sorting on "Name":
fields: [
{ name: 'Id', defaultValue: 0, type: 'int', mapping: 'Id' },
{ name: 'Name', defaultValue: '', type: 'string', mapping: 'Name', sortType: Ext.data.SortTypes.asUCString },
{ name: 'Type', defaultValue: 0, type: 'int', mapping: 'Type' },
{ name: 'CreationDate', type: 'date', mapping: 'CreationDate' }
],
Can anybody point me in the right direction? I'm using extjs 4.0.5
In store you have to set up how the data will display by sorters property:
var store = Ext.create('Ext.data.JsonStore', {
.
.
.
remoteSort: false, //true for server sorting
sorters: [{
property: 'Name',
direction: 'DESC' // or 'ASC'
}],
.
.
.
})
Try calling TreeStore.sort with a sorter config with a sorting callback. A simple field sort won't do in this case because the naive alpha sort isn't what you want. The example at the top of the Ext.util.Sorter doc shows how to do it in a store, but you can just as easily add it to the sorters param of your model.

Querying with SDK2.0: OR filters together

This example in the documentation shows how to query the Rally WS API, using a single item in a filters array:
Ext.create('Rally.data.WsapiDataStore', {
model: userStoryModel,
fetch: true,
filters: [
{
property: 'ScheduleState',
operator: '<',
value: 'Accepted'
}
],
...
I know if I have a second filter to the filters array, it AND's the two filters together. But how would I OR two filters?
You can use Rally.data.QueryFilter's or method to do this:
filters: [
Ext.create('Rally.data.QueryFilter', {
property: 'ScheduleState',
operator: '=',
value: 'Accepted'
}).or(Ext.create('Rally.data.QueryFilter', {
property: 'ScheduleState',
operator: '=',
value: 'Defined'
})
]

need javascript array format

I am looking to create following format in array in javascript.
Each item has:
url -> string (which is login URL)
name -> string
inputs -> array
And each input is:
name -> string
type -> string
value -> string
Please guide me , how to do this in JavaScript
[
{url: 'http://google.com/',
name: 'google',
inputs: [
{ name: 'search-term', type: 'string', value: 'javascript' },
{ name: 'region', type: 'country-code', value: 'IN' }
]
},
{url: 'http://yahoo.com/',
name: 'yahoo',
inputs: [
{ name: 'search-term', type: 'string', value: 'javascript' },
{ name: 'region', type: 'country-code', value: 'US' }
]
}
]
there you go.
on a related note, JSON might be worth looking at once. Though I must say, the above is not json, only json-like.
This would be tricky in a strongly typed language like Java or C#, but it's pretty easy in JavaScript.
Since JavaScript doesn't have strong typing for array values and variables, you can just create an array of object literals. Each object would contain the properties you specified. There's no need to specify the string type on each property--JavaScript will infer that for you.
While this is really easy to do, the drawback is that you're not going to get any type checking, so some code could inadvertently stick an object into one of your string fields and JavaScript won't stop it.
So just beware of the advantages and disadvantages of JavaScript's flexibility, and make sure you're doing server-side sanity checks on your data.
var items =
[
{
url: "http://...",
name: "FOO",
inputs: [
{
name: "Input1",
type: "LeTypeh"
value: "Levalueh"
},
{
name: "Input2 (Foo)",
type: "LeType2a",
value: "Levalue2j"
}
// ... (insert as many comma separated inputs as you need in the foo item
},
{
url: "http://...",
name: "BAR",
inputs: [
{
name: "Input1",
type: "LeTypeh"
value: "Levalueh"
},
{
name: "Input2 (Bar)",
type: "LeType2a",
value: "Levalue2j"
}
// ... (insert as many comma separated inputs as you need in the bar item here
}
//... (insert as many comma separated items as you need in the array here
]

Categories