Select to view content in your preferred language

timing issue -- anyone who is good with deferreds?

4657
21
Jump to solution
11-12-2013 06:05 AM
KaitlynnDavis
Regular Contributor
I'm building an editing application, and I use a custom drop-down menu for one of the fields in my attribute inspector. The drop down is populated by a query, so it's very important that the query function completes before the function that builds the attribute inspector. My problem is timing the query. My map listener map.on("layers-add-result", initEditor); fires initEditor well before my query has had the chance to complete and as a result my map features become disabled. I can fix the problem by pausing the execution of initEditor with an alert box, but obviously this can't be a permanent solution.

I believe a deffered would help ensure that my query task has returned before populating my attribute inspector, but I am weak on the concept. Is there a programmatic way to say map.on("layers-add-result", initEditor) after query returns results?
0 Kudos
21 Replies
JianHuang
Deactivated User
Please take a look at the code snippet:

map.on("layers-add-result", initEditor);

function iniEditor(results){
  //the same code as you already have to build layerInfos in settings.
  var editor = new new esri.dijit.editing.Editor(params,'editorDiv');
  editor.startup();
  //when a layer is removed from the map, recreate the editor widget
  map.on("layer-remove", dojo.hitch(null, recreateEditor, editor));
}

function recreateEditor(editor){
  editor.destroy();
  editor =  new new esri.dijit.editing.Editor(params,'editorDiv');
  editor.startup();
}
0 Kudos
ionarawilson1
Deactivated User
Thank you so much for taking the time to answer this Jian! This is great!!!
0 Kudos