Hi,
Is it possible, and if so how do I use a selection set I've made with the Select Widget with another custom developed widget?
Hi Grant,
Thanks again for your reply, I applied the changes as you guided in above comment but now it throw back a different sort of error "uncaught TypeError : array.forEach is not a function".i read the dojo documentation about dojo/_base/array but i can not see what is wrong in this script. On removing array.forEach ids variable generate empty output.
Hi Fahad,
You will need to add the array module to the define at the top of your code and also as a parameter to the function, see below.
<SPAN class="token function">define</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="string token">'dojo/_base/declare'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'jimu/BaseWidget'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'dojo/_base/array'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'esri/layers/FeatureLayer'</SPAN> <SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">function</SPAN><SPAN class="punctuation token">(</SPAN>declare<SPAN class="punctuation token">,</SPAN> BaseWidget<SPAN class="punctuation token">,</SPAN> array<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
https://dojotoolkit.org/reference-guide/1.10/dojo/_base/array.html
Thank you for your kind reply. I have a simple widget in which a button in defined and on clicking the button i'm trying to define a function which will store OIDs of selected feature in a variable which i then pass on to some non esri webapps to preform some task. I have tried to apply your code in the function i defined for my button but it throws back an error "Uncaught reference error: array is no defined", as i'm also new in javascript i have no idea what i'm doing wrong here. I'll attach the picture of code that i have and it'll a great help if can take a look and can point out what is wrong with this code that i'm trying out.
Get the name of the Id field by calling the objectidField method on a featureLayer.
Then if you call the getSelectedFeatures on a featureLayer you will get an array of Graphic objects.
Use the objectidField name to get the Id of the feature (Graphic) from its attributes array.
var ids = []; array.forEach(this.map.itemInfo.itemData.operationalLayers, function (layer) { var featureLayer = layer.layerObject; array.forEach(featureLayer.getSelectedFeatures(), function (feature) { ids.push(feature.attributes[featureLayer.objectIdField]); }, this); }, this);
I think that is the gist of it. Apologies my javascript is a bit rusty.
These may help:
Select with Feature Layer | ArcGIS API for JavaScript 3.34
Graphic | API Reference | ArcGIS API for JavaScript 3.34
FeatureLayer | API Reference | ArcGIS API for JavaScript 3.34
Hi there i'm also facing this issue can you please elaborate the solution? i'm looking to get OIDs of features selected through select widget.any sort of help / pointers will be appreciated.
I have the answer I was looking for. That will teach me to read the documentation properly in future ...
var count = 0;
array.forEach(this.map.itemInfo.itemData.operationalLayers, function (layer) {
var featureLayer = layer.layerObject;
count += featureLayer.getSelectedFeatures().length;
}, this);
サインインしたメンバーは投稿、更新のフォローなどができます。初めてですか?無料アカウントを登録してください。
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.