I have two json-Mock Files:
Types.json:
[{
"TypeID": 1
}, {
"TypeID": 2
}]
Items.json:
[{
"ItemID": 12345,
"TypeID": "1",
}, {
"ItemID": 54321,
"TypeID": "2",
}]
My List Binding:
oView.bindElement({
path : "/Items",
filters: [ new sap.ui.model.Filter("TypeID", sap.ui.model.FilterOperator.EQ, oArgs.TypeID) ],
events : {
change: this._onBindingChange.bind(this),
dataRequested: function (oEvent) {
oView.setBusy(true);
},
dataReceived: function (oEvent) {
oView.setBusy(false);
}
}
});
My code ignores the filter and shows both Items although only one of them have the right TypeID (1 resp 2).
Console Output: oArgs.TypeID is defined and contains 1 resp 2.
Element binding is meant for binding UI elements to a specific object in the model data. You are trying to use bindElement to bind UI elements to a set of data.
Because bindElement always binds to a singleton, the filter parameter doesn't make sense and does not exist.
Related
I have this JSON
{
"srv_config": [{
"name": "db1",
"servers": ["srv1", "srv2"],
"prop": [{"source":"aa"},"destination":"bb"},{"source":"cc"},"destination":"cc"},]
}, {
"name": "db2",
"servers": ["srv2", "srv2"],
"prop": [{"source":"dd"},"destination":"dd"},{"source":"ee"},"destination":"ee"},]
}
]
}
I try to build a JMESPath expression to select the prop application in each object in the main array, but based on the existence of a string in the servers element.
To select all props, I can do:
*.props [*]
But how do I add condition that says "select only if srv1 is in servers list"?
You can use the contains function in order to filter based on a array containing something.
Given the query:
*[?contains(servers, `srv1`)].prop | [][]
This gives us:
[
{
"source": "aa",
"destination": "bb"
},
{
"source": "cc",
"destination": "cc"
}
]
Please mind that I am also using a bit of flattening here.
All this run towards a corrected version of you JSON:
{
"srv_config":[
{
"name":"db1",
"servers":[
"srv1",
"srv2"
],
"prop":[
{
"source":"aa",
"destination":"bb"
},
{
"source":"cc",
"destination":"cc"
}
]
},
{
"name":"db2",
"servers":[
"srv2",
"srv2"
],
"prop":[
{
"source":"dd",
"destination":"dd"
},
{
"source":"ee",
"destination":"ee"
}
]
}
]
}
I am trying to hook select2 when an element has class "select2picker" i am also customising if the source of the dropdown list is an array. My code below
$('.select2picker').each(function() {
var settings = {};
if ($(this).attr('data-json')) {
var jsonValue = JSON.parse($(this).attr('data-json')).val());
settings = {
placeholder: $(this).attr('data-placeholder'),
minimumInputLength: $(this).attr('data-minimumInputLength'),
allowClear: true,
data: jsonValue
}
}
$(this).select2(settings);
});
but the result is horrible it fails to hook all the select2 dropdownlist
but when I comment out the data property, the output shows perfect (but the data binding goes missing)
My array looks like the following
[ { "id": "2015-0152", "text": "2015-0152" }, { "id": "2015-0153", "text": "2015-0153" }, { "id": "2016-0001", "text": "2016-0001" }, { "id": "2016-0002", "text": "2016-0002" }, { "id": "2016-0003", "text": "2016-0003" }, { "id": "2016-0004", "text": "2016-0004" }, { "id": "2016-0005", "text": "2016-0005" }, { "id": "2016-0006", "text": "2016-0006" }, { "id": "2016-0007", "text": "2016-0007" }, { ... }, { "id": "2015-0100", "text": "2015-0100" }, { "id": "2015-0101", "text": "2015-0101" }, { "id": "2015-0080", "text": "2015-0080" }, { "id": "2015-0081", "text": "2015-0081" }, { "id": "2015-0090", "text": "2015-0090" }, { "id": "2015-0102", "text": "2015-0102" }, { "id": "2015-0112", "text": "2015-0112" }, { "id": "2015-0128", "text": "2015-0128" }, { "id": "2015-0136", "text": "2015-0136" } ]
I am really confused about what is going wrong. Any idea?
Select2 version: 3.4.8
This line gives an error: var jsonValue = JSON.parse($(this).attr('data-json')).val());
Should be: var jsonValue = JSON.parse($(this).attr('data-json'));.
Also this line in your question:
i am also customising if the source of the dropdown list is an array
Indicates to me that it might also not be an array. In that cause you should check if it is an array before you pass the data to select2.
EDITED: Another thing that came to my mind was the following.
If you're using data properties for the placeholder I don't think you need to pass the values of those properties to select2 a second time like you do here
placeholder: $(this).attr('data-placeholder'),
minimumInputLength: $(this).attr('data-minimumInputLength'),
Might be that you need to pick one of the two (either pass it along in your settings, or use an attribute). As select2 looks at the data attributes to get a value.
I checked if the above was correct turns out it isn't. It works fine in this fiddle: https://jsfiddle.net/wL7oxbpv/
I think there is something wrong with your array data. Please check that.
Hey guys so I am currently using jqgrid with json data and it currently reads in fine but i am having some difficulties getting an embeded object to read into the grid. So my json data looks something like this:
{"total":1,"page":"1","records":1,"rows":[{"Cell1":1,"Cell2":"stuff","Cell3":{"date":"2013-06-02 10:56:00","timezone_type":3,"timezone":"UTC"}}]}
Does anyone know how i can get jqgrid to read in Cell3 as one piece of data and interpret it to just display the date and time?
my current json reader is as follows:
jsonReader : {
root:"rows",
page: "page",
total: "total",
records: "records",
repeatitems: false,
id: "0"
}
Thanks again everyone
First of all the options jsonReader: {repeatitems: false, id: "0"} are incorrect. Integer values of id can be used in case of usage default repeatitems: true setting. In the case the data which represent the row of the grid looks like array ["1", "Cell2"] and not as object with named properties {"Cell1": 1, "Cell2": "stuff"}. You should use jsonReader: {repeatitems: false, id: "Cell1"} if Cell1 contains the value which you want to use as unique id of the row of the grid.
Now back to your main question. I recommend you to change format of the data from
{
"total": 1,
"page": "1",
"records": 1,
"rows": [
{
"Cell1": 1,
"Cell2": "stuff",
"Cell3": {
"date": "2013-06-02 10:56:00",
"timezone_type": 3,
"timezone": "UTC"
}
}
]
}
to
{
"total": 1,
"page": "1",
"records": 1,
"rows": [
{
"Cell1": 1,
"Cell2": "stuff"
}
],
"userdata": {
"1": {
"date": "2013-06-02 10:56:00",
"timezone_type": 3,
"timezone": "UTC"
}
}
}
I want comment my suggestion so that it could be clear for other users too. The column Cell1 contains the id. The structure of userdata which I suggest is the map from rowid (the value of Cell1) and the custom information which you need save as "Cell3" originally.
If you need somewhere in your code to have the "Cell3" value the code will be like below
onSelectRow: function (rowid) {
var cell3 = $(this).jqGrid("getGridParam", "userData")[rowid];
// now you can use cell3 which coniains the object like
// {
// "date": "2013-06-02 10:56:00",
// "timezone_type": 3,
// "timezone": "UTC"
// }
}
I am having a JSON data like below.
{
"divisions": [{
"name": "division1",
"id": "div1",
"subdivisions": [{
"name": "Sub1Div1",
"id": "div1sub1",
"schemes": [{
"name": "Scheme1",
"id": "scheme1"
}, {
"name": "Scheme2",
"id": "scheme2"
}]
}, {
"name": "Sub2Div1",
"id": "div1sub2",
"schemes": [{
"name": "Scheme3",
"id": "scheme3"
}]
}
]
}]
}
I want to read this into a TreeStore, but cannot change the subfields ( divisions, subdivisions, schemes ) to be the same (eg, children).
How can achieve I this?
When nested JSON is loaded into a TreeStore, essentially the children nodes are loaded through a recursive calls between TreeStore.fillNode() method and NodeInterface.appendChild().
The actual retrieval of each node's children field is done within TreeStore.onNodeAdded() on this line:
dataRoot = reader.getRoot(data);
The getRoot() of the reader is dynamically created in the reader's buildExtractors() method, which is what you'll need to override in order to deal with varying children fields within nested JSON. Here is how it's done:
Ext.define('MyVariJsonReader', {
extend: 'Ext.data.reader.Json',
alias : 'reader.varijson',
buildExtractors : function()
{
var me = this;
me.callParent(arguments);
me.getRoot = function ( aObj ) {
// Special cases
switch( aObj.name )
{
case 'Bill': return aObj[ 'children' ];
case 'Norman': return aObj[ 'sons' ];
}
// Default root is `people`
return aObj[ 'people' ];
};
}
});
This will be able to interpret such JSON:
{
"people":[
{
"name":"Bill",
"expanded":true,
"children":[
{
"name":"Kate",
"leaf":true
},
{
"name":"John",
"leaf":true
}
]
},
{
"name":"Norman",
"expanded":true,
"sons":[
{
"name":"Mike",
"leaf":true
},
{
"name":"Harry",
"leaf":true
}
]
}
]
}
See this JsFiddle for fully working code.
I am looking query the JSON data based on some where conditions for ex. list the person names whose cell no is 777-777-7777.
pl let me know what are query capabilities in JSON.
var json = [{
"name": "senthil",
"Phoneno": [{
"Home": "111-111-1111"
},
{
"Cell": "222-222-2222"
},
{
"Office": "333-333-3333"
}
],
"City": "Hartford"
},
{
"name": "kumar",
"Phoneno": [{
"Home": "444-555-6666"
},
{
"Cell": "777-777-7777"
},
{
"Office": "888-888-8888"
}
],
"City": "Austin"
},
];
var people = json.filter(function(el)
{
return el.Phoneno.some(function(number)
{
return number.Cell == "777-777-7777";
});
});
This uses the Array.filter and Array.some functions from ECMAScript 5. filter returns an array of the elements that pass a test. some returns true if any element in an array passes the test.
For browsers that don't support it, you can use the code at MDC.
This will almost certainly not be faster than the obvious for-loop approach.
As a note, if every person can have up to one phone number per type, a simpler representation would be:
"Phoneno": { "Home": "111-111-1111",
"Cell": "222-222-2222",
"Office": "333-333-3333"
}
Also, JSON technically refers to the text representation, not actual JavaScript objects.