AnsweredAssumed Answered

Registry Error in Custom Widget

Question asked by abhinavsharma1 on Jan 24, 2018
Latest reply on Jan 26, 2018 by kenbuja

//Updated define //

//updated last line from fields to fieldNames// 

Hi everyone, I am attempting to expand my widget by adding in a renderer that is is available to the end user. I have been working my way through the following ESRI Sample. The sample is for a mapservice and not a feature layer but I do not see why the same idea can not be applied. The issue is in bold. It stops at both of those instances. I have used console.log to see if there is any difference in the object that is being passed. ( Looked at the object in the sample and compared to my own) and the only difference i can find is when i print out fieldname after the push: using (console.log("fieldnames", fieldNames)

 

the sample looks like this:

fieldnames

  1. {identifier: "value", label: "name", items: Array(2)}
    1. identifier:"value"
    2. items:Array(10)
      1. 0:
        1. name:["FIPS"]
        2. value:["FIPS"]
        3. _0:0
        4. _RI:true
        5. _S:{_arrayOfAllItems: Array(10), _arrayOfTopLevelItems: Array(10), _loadFinished: true, _jsonFileUrl: undefined, _ccUrl: undefined, …}
        6. __proto__:Object 

whereas from my widget it looks like this:

fieldnames

  1. {identifier: "value", label: "name", items: Array(1)}
    1. identifier:"value"
    2. items:Array(19)
      1. 0:
        1. name:"OBJECTID"
        2. value:"OBJECTID"

 

 

TypeError: Cannot read property 'on' of undefined

define(
['dojo/_base/declare',
'jimu/BaseWidget',
"esri/toolbars/draw",
"esri/toolbars/edit",
"esri/graphic",
"esri/request",
"esri/config",
"esri/tasks/ClassBreaksDefinition",
"esri/tasks/UniqueValueDefinition",
"esri/tasks/AlgorithmicColorRamp",
"esri/tasks/GenerateRendererParameters",
"esri/tasks/GenerateRendererTask",
"esri/layers/LayerDrawingOptions",
"esri/layers/FeatureLayer",
"esri/layers/Field",
"esri/symbols/SimpleMarkerSymbol",
"esri/symbols/SimpleLineSymbol",
"esri/symbols/SimpleFillSymbol",
"esri/dijit/editing/TemplatePicker",
"dojo/_base/array",
"dojo/_base/event",
"dojo/_base/lang",
"dojo/parser",
"dijit/registry",
"dojo/data/ItemFileReadStore",
"dojox/grid/DataGrid",
"dijit/form/FilteringSelect",
"dojo/domReady!"],
function(declare, BaseWidget, Draw, Edit, Graphic, esriRequest, esriConfig,
ClassBreaksDefinition, UniqueValueDefinition, AlgorithmicColorRamp,
GenerateRendererParameters, GenerateRendererTask, LayerDrawingOptions,
FeatureLayer,Field,
SimpleMarkerSymbol, SimpleLineSymbol, SimpleFillSymbol,
TemplatePicker,
arrayUtils, event, lang, parser, registry, ItemFileReadStore, DataGrid, FilteringSelect) {
//To create a widget, you need to derive from BaseWidget.
return declare([BaseWidget], {
// DemoWidget code goes here
//please note that this property is be set by the framework when widget is loaded.
//templateString: template,
baseClass: 'jimu-widget-ROP',
postCreate: function() {
this.inherited(arguments);
console.log('postCreate');
},
startup: function() {
///INICIO/////
parser.parse();
// refer to "Using the Proxy Page" for more information: https://developers.arcgis.com/javascript/3/jshelp/ags_proxy.html
esriConfig.defaults.io.proxyUrl = "/proxy/";
map= this.map;
map.on("layers-add-result", initEditing);

var landusePolygonLayer = new FeatureLayer("MyLayer", {
id: "canada_Risk",//confirm works
mode: FeatureLayer.MODE_ONDEMAND,
outFields: ["*"]
});
console.log("LayerInfo", landusePolygonLayer)
map.addLayers([landusePolygonLayer]);
//fieldInfo
var canadaFields = esriRequest({
url:"https://services7.arcgis.com/Layer",
content:{
f: "json"
},
callbackParamName : "callback"
});
console.log("fields", canadaFields)
canadaFields.then(function(resp){
var fieldNames, fieldStore;
fieldNames = { identifier : "value", label: "name", items: []};
console.log("fields", fieldNames)
arrayUtils.forEach(resp.fields,function(f){
fieldNames.items.push({"name": f.name, "value": f.name});
console.log("fieldnames", fieldNames)
});
fieldStore = new ItemFileReadStore({ data:fieldNames});
console.log("store", fieldStore)
registry.byId("fieldNames").set("store", fieldStore);
}, function(err){
console.log("failed to get field names: ", err);
});
//update when field name changes
registry.byId("fieldNames").on("change", getData);

Outcomes