Mode one: Querytask mode: This method is used for conditional queries on individual layers (cannot be queried across layers)
1. Create a Query object
1 new esri.tasks.Query ();
2. Setting parameters for a query object
1 true ; 2 query.outfields = [' ID, name, ... '] // Query result set returned field 3 query.where = ' ID = ' + ID; // Query Criteria
3. Create a Querytask object
1 new esri.tasks.QueryTask (' http://... '); // Create a Querytask object with parameters that connect to the layer you want to query
4. Query and result set processing
1 // Pass the query object as a parameter to the Execute method, results as the result set 2 if (Results.features.length > 0) { // callback function 3... // working with result sets 4 Else {5... // result set is empty 6 }7 });
Mode two: Findtask mode: This method is used for fuzzy queries at multiple levels under the same layer (can be cross-layer and only fuzzy query)
1. Create the Findtask object:
1 New // Layerurl Connection for the layer to be queried
2. Creating the Params Parameter object
1 New esri.tasks.FindParameters (); 2 params.layerids = [0, 1, 2, ...]; // set up a query layer list 3 params.searchfields = [' Swchname ']; // set the fields of the query layer to blur the query based on the Swchname field 4 params.searchtext = swchname; // set keywords for fuzzy queries 5 true; // returns the geometry of the spatial query so that the result of the return value is superimposed on the map in the form of an icon
3. Query and result set processing
1 // callback function 2 if (Results.length > 0) {3... // working with result sets 4 Else {5... // result set is empty 6 }7 });
about how ArcGIS for javascrept queries ArcGIS Server layer Information