AnsweredAssumed Answered

Get searchWidget Result as json object

Question asked by Henseki on Aug 10, 2017
Latest reply on Aug 10, 2017 by rscheitlin

Hi Again,

 

My searchwidget is working alright, it displays the search with a popup template. The problem now is to get the result of the search as a json  object  or a table.

 

I have search the api references, and its the search-complete that returns search as an object. my code isn't right. Any help please see below,

 

// Search
 
  var search = new Search({
    view: view
  });
  search.defaultSource.withinViewEnabled = true; // Limit search to visible map area only
  view.ui.add(search, "top-right"); // Add to the map

  // Add the trailheads as a search source
  search.sources.push({
    featureLayer: trailsLayer,
     searchFields: ["Postcode", "UPRN", "ADDRESS" ],
  displayField: "Postcode",
  exactMatch: false,
  outFields: ["*"],
   resultGraphicEnabled: true,
    name: "Postcode",
  placeholder: "example:  CM2 0HU",
    popupTemplate: { // autocasts as new popupTemplate()
        title: "Post Code: {Postcode}</br>UPRN: {UPRN}</br>ADDRESS: {ADDRESS}",
        overwriteActions: true
     
      }
  });
     
  search.sources.push({
    featureLayer: trailsLayerr,
     searchFields: ["Postcode", "UPRN", "ADDRESS" ],
  displayField: "Postcode",
  exactMatch: false,
  outFields: ["*"],
   resultGraphicEnabled: true,
    name: "Postcode",
  placeholder: "example:  CM2 0HU",
    popupTemplate: { // autocasts as new popupTemplate()
        title: "Post Code: {Postcode}</br>UPRN: {UPRN}</br>ADDRESS: {ADDRESS}",
        overwriteActions: true
     
      }
  });
 
  function searchcomplete( search-complete) {
    view.popup.open({   
activeSourceIndex: Number,
errors: Error[],
numResults: Number,
searchTerm: String,
results: Object[],

}

 
    });
 
 
searchWidget.on("search-complete", function(event){
  // The results are stored in the event Object[]
  console.log("Results of the search: ", event);
});

 

 

});
 
 
 
 
 
 

});</script>
</head>
<body>
  <div id="viewDiv"></div>

Outcomes