Ember route with dynamic filter / search criterias

后端 未结 3 2142
礼貌的吻别
礼貌的吻别 2020-12-30 17:33

With the following problem I got stuck now for days. My use case is that I have a database with millions of addresses. From an web-application I would like to search them, d

3条回答
  •  一个人的身影
    2020-12-30 18:36

    To take advantage of ember data you could do it this way. Assuming you have a model like this:

    App.SearchResult = DS.Model.extend({
      firstName: DS.attr('string'),
      lastName: DS.attr('string'),
      city: DS.attr('string')
    });
    

    and then you do in your Route's model hook you do this:

    App.SearchResultsRoute = Ember.Route.extend({
      model: function(params){
        return App.SearchResult.find({firstName:params.firstName,lastName:params.lastName,city:params.city})
      }
    });
    

    this way the RESTAdapter will automatically issue a request like your example:

    http://localhost/#/searchresults?firstname=xxx&lastname=xxx&city=xxx
    

    Hope it helps

提交回复
热议问题