How Do I Return An Array From My Query?

3449
2
Jump to solution
06-12-2015 11:45 AM
ChrisSergent
Regular Contributor III

I have the following query that does not complete and I receive an error:

 on(dom.byId("btnSupportNext"),"click",function(){
            console.log("Next Works");
            var query = new esriQuery();
            var queryTask = new QueryTask(config.signLayerUrl);


            query.where = "SUPPORTID = " + document.getElementById("supportId");
            queryTask.execute(query,function(results){
                console.log(results);
            })

The latest github code is here: csergent45/streetSigns at 754f9558a6a37e1e8a825b860e781d9ea4e4ba3d · GitHub

And I have re-published the application here: Street Signs

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Chris,

  Here is a sample using your service.

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <!--The viewport meta tag is used to improve the presentation and behavior of the samples
      on iOS devices-->
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
    <title>Query State Info without Map</title>

    <script src="http://js.arcgis.com/3.13/"></script>
    <script>
      require([
        "dojo/dom", "dojo/on",
        "esri/tasks/query", "esri/tasks/QueryTask", "dojo/domReady!"
      ], function (dom, on, Query, QueryTask) {

        var queryTask = new QueryTask("http://maps.decaturil.gov/arcgis/rest/services/test/StreetSignTest/FeatureServer/0");

        var query = new Query();
        query.returnGeometry = false;
        query.outFields = ["*"];

        on(dom.byId("execute"), "click", execute);

        function execute () {
          query.where = "SUPPORTID = " + dom.byId("supportId").value;
          queryTask.execute(query, showResults);
        }

        function showResults (results) {
          var resultItems = [];
          var resultCount = results.features.length;
//This is an array of results
          for (var i = 0; i < resultCount; i++) {
            var featureAttributes = results.features.attributes;
            for (var attr in featureAttributes) {
              resultItems.push("<b>" + attr + ":</b>  " + featureAttributes[attr] + "<br>");
            }
            resultItems.push("<br>");
          }
          dom.byId("info").innerHTML = resultItems.join("");
        }
      });
    </script>
  </head>

  <body>
    US state name :
    <input type="text" id="supportId" value="691">
    <input id="execute" type="button" value="Get Details">
    <br />
    <br />
    <div id="info" style="padding:5px; margin:5px; background-color:#eee;">
    </div>
  </body>
</html>

View solution in original post

2 Replies
RobertScheitlin__GISP
MVP Emeritus

Chris,

  Here is a sample using your service.

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <!--The viewport meta tag is used to improve the presentation and behavior of the samples
      on iOS devices-->
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
    <title>Query State Info without Map</title>

    <script src="http://js.arcgis.com/3.13/"></script>
    <script>
      require([
        "dojo/dom", "dojo/on",
        "esri/tasks/query", "esri/tasks/QueryTask", "dojo/domReady!"
      ], function (dom, on, Query, QueryTask) {

        var queryTask = new QueryTask("http://maps.decaturil.gov/arcgis/rest/services/test/StreetSignTest/FeatureServer/0");

        var query = new Query();
        query.returnGeometry = false;
        query.outFields = ["*"];

        on(dom.byId("execute"), "click", execute);

        function execute () {
          query.where = "SUPPORTID = " + dom.byId("supportId").value;
          queryTask.execute(query, showResults);
        }

        function showResults (results) {
          var resultItems = [];
          var resultCount = results.features.length;
//This is an array of results
          for (var i = 0; i < resultCount; i++) {
            var featureAttributes = results.features.attributes;
            for (var attr in featureAttributes) {
              resultItems.push("<b>" + attr + ":</b>  " + featureAttributes[attr] + "<br>");
            }
            resultItems.push("<br>");
          }
          dom.byId("info").innerHTML = resultItems.join("");
        }
      });
    </script>
  </head>

  <body>
    US state name :
    <input type="text" id="supportId" value="691">
    <input id="execute" type="button" value="Get Details">
    <br />
    <br />
    <div id="info" style="padding:5px; margin:5px; background-color:#eee;">
    </div>
  </body>
</html>
ChrisSergent
Regular Contributor III

Thanks I would have marked this correct sooner, but it's been an unusually busy week.

0 Kudos