Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Re : Cascaded dropdowns/models

$
0
0
If you have dependent lists, that's a great reason to use can.compute. Using a compute in your dependent list you can respond to the changes in the parent dropdown. For example, let's say your parent sets a property called 'selected' on some state map you have, you could then do (pseudocode):

  1. var data = new can.Map({selected: 'some default'});
  2. var child = can.compute(function() {
  3.   var cityName = data.attr('selected');
  4.   var list = new Cities.List([]);
  5.   Cities.findAll({ name: cityName }).then(function(newList) {
  6.     list.replace(newList);
  7.   });
  8.   return list;
  9. });
When data.selected gets set, the child list will automatically recompute itself. Does that make sense?

Viewing all articles
Browse latest Browse all 3491

Trending Articles