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

Re : Cascaded dropdowns/models

$
0
0
It's also worth noting that you can create new lists passing deferreds, so you could just as easily use new can.List(Cities.findAll) or otherwise use new Cities.List({ state: 'CA'}) to create a Cities.List that will add in items when resolved.

Also, the main issue with the approach presented above is that it'll always return a new list instance, and so it'll always make an ajax request, and it'll never return the same list instance.

A better approach would be to do this within a component, and make a compute that generates a deferred, and to listen to that and update your listen. There are lots of options as to how to do this.

For example:

  1. var Contact = can.Component.extend({
  2.   tag: 'contact',
  3.   scope: {
  4.     query: function() {
  5.       return Cities.findAll({ state: this.attr('state') });
  6.     }
  7.   },
  8.   events: {
  9.     '{query} change': function() {
  10.       var query = this.scope.attr('query');
  11.       this.scope.attr('cities' , new Cities.List(query));
  12.     }
  13.   }
  14. });

Viewing all articles
Browse latest Browse all 3491

Trending Articles