简体   繁体   中英

Ember.js change router statement within view

Suppose I have a view:

Cellar.SearchTextField = Ember.TextField.extend({
    insertNewline: function(){
      // Cellar.SearchController.loadResults();
    }
});

And I have a route:

Cellar.Router.map(function() {
  this.route('search', { path: '/search'});
});

How can I change app url to host/#/search? when submitting the view's textfield? Or what is the best and most logic way to implement search forms in ember applications?

I get this working using:

App.SearchField = Ember.TextField.extend({
    insertNewline: function() {        
        this.get('controller').transitionToRoute('search', this.get('value'));
    }
});

This will transition to search route, so you can load and filter the data on model hook.

Here is a jsfiddle with the demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM