Addition of named array breaks Kendo dataSource bind to JSON - javascript

I'm binding a JS KendoUI dropdownlist to JSON (not using a model) which recently has been changed by adding a named array to the object (in efforts to format the JSON for a Kendo TreeView control). This broke a few things of course. The original JSON format looked like this (an array of objects):
[
{
"COLUMN_NAME": "OBJECTID",
"DATA_TYPE": "esriFieldTypeOID",
"CATEGORY": "Feature Data"
},
{
"COLUMN_NAME": "Brand",
"DATA_TYPE": "esriFieldTypeString",
"CATEGORY": "Feature Data"
},...
]
now it looks like this (an object with a named array, with objects):
{
"Hydrant": [
{
"COLUMN_NAME": "OBJECTID",
"DATA_TYPE": "esriFieldTypeOID",
"CATEGORY": "Feature Data"
},
{
"COLUMN_NAME": "Brand",
"DATA_TYPE": "esriFieldTypeString",
"CATEGORY": "Feature Data"
},...
],
"DisplayField": "Description",
"DefaultField" : "HydrantID"
}
I assumed I could simply define the schema to "Hydrant" or set the dataText/ValueFields to "Hydrant.COLUMN_NAME" but no luck. What am I overlooking? I am binding this JSON format response to a dropdownlist using the "COLUMN_NAME" to populate it.
bonus: how could I use the "DefaultField" to set the default selection in the dropdownlist?
Thanks in advance!

You can use the schema.data field of the DataSource configuration to identify the field from the response to use for its data:
schema: { data: 'Hydrant' }

Related

How to link two json array data's with Google apps script

Using a UrlFetchapp request, I retrieve data in json format in a sheet sheet, for non-table objects the processing is not that hard, but when it comes to tables it's a little less Easy,
I retrieve and display the label content in 4 columns in my sheets sheet by browsing the array object "feezeInformationList" then "feezeTypeCode" then "label", outside the "feezeInformationList" object we find additional data to the label, which is present in another array object, which is "glcfeezeInclusionInformationList", the complementary data is boolean and it is "glcfeezeIsIncludedInPrice" next to each column label, I would like to retrieve the true or false status of each label using maybe as input , the code attribute, here for example "2282".
"data": [
{
"glcfeezeInclusionInformationList": [
{
"feezeTypeCode": {
"code": "2282",
"description": "",
"label": "MMG"
},
"glcfeezeIsIncludedInPrice": true
}
feezeInformationList [
"feezeTypeCode": {
"code": "2282",
"description": "",
"label": "MMG"
},
]
Any help would be appreciated! thanks

Is there any Dojo treegrid limits to avoid "Sorry, an error occurred" message appear?

I cannot find any info if there is any limitations for dojo treegrid JSON store. Here is my simple store. It works perfect but fails if it has thousands of items. So is there a limit for number of items or childItems? Or is there a limit for JSON object size?
{
"identifier": "id",
"label": "name",
"items": [
{
"id": "id1",
"type": "year",
"year": "2018",
"childItems": [
{
"id": "id0",
"projname": "Project 1"
},
{
.....
}
]
},
{
.....
}
]
}
Dojo treegrid mostly shows this error message when it finds multiple items with the same id, so you want to make sure all "id" attributes in your "items" list have unique value. In my test setup I was able to load more than 20000 rows so most probably you have malformed data. Supply following option to grid to log any fetch related errors:
onFetchError: function(err, req){
console.log(err);
}
Hope it helps.

Error getting data from Kendo UI dataset

dsDetails = new kendo.data.DataSource({
transport: {
read: {
url: PRODUCTDETAILAPI,
dataType: "json",
data: { "site_key": SITEKEY, "id": id }
}
}
});
dsDetails.fetch(function() {
var myData = dsDetails.data();
console.log(myData);
// bind stuff here
});
The API call is returning the following data (so I know that is working):
{
"main_category": "Gifts",
"expires_on": null,
"html_address": "678 Sterling Drive\u003Cbr/\u003ESuite 102\u003Cbr/\u003ESanford FL 32771",
"address": "678 Sterling Drive Suite 102, Sanford Florida 32771",
"status": "Visible",
"rating": 5, "sub_category": "Gift Baskets",
"quantity": 92, "categories": ["Gifts: Gift Baskets"], "title": "Luggage Duffel",
"price": 12210, "images": [], "short_address": "Sanford FL",
"short_title": "Luggage Duffel",
"posted_at": "2011/09/23",
"category": "Gifts: Gift Baskets",
"id": "product_listing_88",
"price_note": "",
"description": "Black, 60 in long",
"seller": "Morning Star Media Group"
}
When I run this code I get the following error:
Uncaught TypeError: Object #<Object> has no method 'slice'
Edit: Based on the selected answer, I replace this kendo dataset code with a standard jQuery .ajax call and it worked fine. My brain was temporarily stuck within the confines of the Kendo framework.
The dataSource is used to get collection of objects from the server. This exception is thrown when the item returned from the server is not the collection. Instead it is an object which has a field that actually holds the array.
If the dataset (array) that you want to use is one of the fields in the returned object, you should use dataSource.schema.data configuration to specify that field, so the dataSource can understand in which field from the response to search the collection.

How do I access values in a d3 json file with nested array objects

Previously I was using a json file with the following format:
[{"lat":43.788458853157117,"lng":-79.282781549043008,"category":"volunteer","name":"Rita","url":"", "description":"xxx is a member of 13"},{"lat":43.7,"lng":-79.4,"category":"organization","name":"TCAN","url":"http://tcan.ca","description":"Lorem ipsum"}]
Now I am attempting to generate the json file from a Drupal site and am getting the following structure. How can I reference the lowest level fields. I have looked at examples using d3.net but have not found any that apply.
{
"organizations": [
{
"member": {
"field_category": "organization",
"body": "A network of organizations in Toronto devoted to climate change mitigation and adaptation.",
"URL": "xxx.ca",
"title": "Toronto Climate Action Network",
"field_lat": 43.7,
"field_long": -79.4
}
},
{
"member": {
"field_category": "abc",
"body": "xxx.",
"URL": "",
"title": "yyy",
"field_lat": 43.7,
"field_long": -79.28
}
}
]
}
Assuming that your data is stored in the variable data:
var bottom = data.organizations.map(function(d) { return d.member; });

ExtJS Grid Selection Model

I have a ExtJS grid with a store mapped to it.
The JSON response for the store contains 20 fields, but I have mapped only 10 fields in the store. Is it possible for me to obtain the other 10 fields without me having to map them in the store or is it necessary for me to map all the fields to the store. Doing this on row select event of the grid. As for the code, I am able to create the grid, map the store, fire the event and even get the record for the selected row with the mapped 10 field.
Any suggestions ??
As requested by Shekhar :
Store definition
Ext.define('gdoc.store.PrintPaperStore', {
extend: 'Ext.data.Store',
constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
autoLoad: true,
storeId: 'PrintPaperStore',
proxy: {
type: 'ajax',
url: 'urlToRetrieveTheJSON',
reader: {
type: 'json',
root: 'root'
}
},
fields: [{
mapping: 'value',
name: 'value'
},
{
mapping: 'display',
name: 'display'
}
]
}, cfg)]);
}
});
The JSON Response :
{
"root": [{
"value": "COATED115",
"display": "Coated recycled paper (115gms)",
"description": "Good quality",
"extra": "EXTRA INFO"
}, {
"value": "COATED135",
"display": "Coated recycled paper (135gms)",
"description": "Good quality"
}, {
"value": "OFFSET",
"display": "Offset recycled paper (80gms)",
"description": "Good quality",
"extra": "EXTRA INFO"
}, {
"value": "OTHER",
"display": "Other paper (client to order)",
"description": "Good quality",
"extra": "EXTRA INFO"
}]
}
As you can see I have mapped only value and display from the JSON response in the store.
Is it possible for me to retrieve values of description and extra without me having to map them in the store.
You can access the .raw property on the model, which will contain the raw JSON from the reader.
No. The model, or store, must set all the fields you want to have available from the JSON data.
I'm confused as to why you don't want to map the extra fields? It's it purely time saving and hoping there was a quicker way to get access to the data? Or are you expecting the fields names to be dynamic?
If it's the dynamic reason, take a look at this post for a solution. Dynamic model with ExtJS 4

Categories

Resources