I created a custom widget and I need create a queryTask to a table in the map. But I can not use new QueryTask. How I can do it?

374
1
05-29-2017 08:28 PM
andreacarina
New Contributor

define([
'dojo/_base/declare',
'jimu/BaseFeatureAction',
'jimu/WidgetManager',
'esri/tasks/query',
'esri/tasks/QueryTask'

], function(declare, BaseFeatureAction, WidgetManager){

var clazz = declare(BaseFeatureAction, {

iconFormat: 'png',

isFeatureSupported: function(featureSet){
return featureSet.features.length == 1 && featureSet.features[0].attributes.state_name != undefined && featureSet.features[0].attributes.state_name == 'Montana';
},

onExecute: function(featureSet){
WidgetManager.getInstance().triggerWidgetOpen(this.widgetId)
.then(function(myWidget) {
var queryTask = new QueryTask("http://services2.arcgis.com/zjX47EEgMzOqxwh7/ArcGIS/rest/services/Mapa/FeatureServer/1");
var query = new Query();
query.returnGeometry = false;
query.outFields = [
"Bocas"
];

query.text = "EquipoId = 'Eq1'";
queryTask.execute(query, showResults);

function showResults(results) {
var resultItems = [];
var resultCount = results.features.length;
}


myWidget.ViewImage(resultCount);
});
}

});
return clazz;
});

0 Kudos
1 Reply
KenBuja
MVP Honored Contributor

You have to add in the arguments in the function to tell the code what QueryTask and Query are. If you examine the console, you should see errors indicating this.

0 Kudos