Ember route with dynamic filter / search criterias

后端 未结 3 2146
礼貌的吻别
礼貌的吻别 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:34

    I've got URL that contains information about news page number and depending on this it sends and ajax call. My router looks like:

    App.Router.map(function() {
        this.resource('news', { path: '/n/:id' });
    });
    

    But you could also do it like:

    App.Router.map(function() {
            this.resource('searchresults', { path: '/searchresults/:lastname/:firstname/:city' });
        });
    

    And your URL would look like this:

    http://localhost/#/searchresults/king/stephen/somecity
    

    Then you just specify:

    App.SearchresultsRoute = Em.Route.extend({
        model: function(params) {
            var lastname = params.lastname;
                var firstname = params.firstname;
                var city = params.city;
                someFunction(lastname, firstname, city);
        }
    });
    

    I hope my answer helped you. Have a nice day!

提交回复
热议问题