1

The code below shows how sel1 updates sel2 based on its value.

var dict = {
  'a': {
    'foo': 321 
  },
  'b': {
    'foo': 123
  }
};

// Callback functions
var updateSel2 = function(k) {
  var sel2Items = Object.keys(dict[k]);
  
  sel2.items().reset();
  
  sel2Items.forEach(function(item) {
    sel2.items().add(item);
  });
  
};

var sel2Behavior = function(v) { print(v) };

// Selectors
var sel1 = ui.Select({
  items: Object.keys(dict),
  onChange: updateSel2
});

var sel2 = ui.Select({
  onChange: sel2Behavior
});

print(sel1);
print(sel2);

When sel2 is updated for the first time, the sel2Behavior function works perfectly.

When I change the value of sel1 again, since sel2 will have the same value (foo), the callback function does not work.

What could be the reason? And how can I fix this?

1 Answer 1

1

At the bottom of updateSel2, call setValue() to reset the value to null (with trigger = false)

sel2.setValue(null, false)

https://code.earthengine.google.com/99ecc23528a8c676c8ebd11dd69a183b

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.