简体   繁体   English

Ember.js在视图中更改路由器语句

[英]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? 如何将应用程序网址更改为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. 这将过渡到搜索路线,因此您可以在model挂钩上加载和过滤数据。

Here is a jsfiddle with the demo 是一个演示的jsfiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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