我有以下代码,当输入搜索查询并按下输入按钮或单击提交按钮时,它会调用 transitionToRoute('search') 。
但是,我的路由器仍然不会在它说的模板中显示 searchQuery:
<p>You searched for: "{{searchQuery}}"</p>
http://www.example.com/#/search/[object Object]
并且 URL在搜索某些东西时看起来像(这对我来说似乎不正确)。
(完整代码可以查看:http: //jsfiddle.net/Mn2yy/1/)这是相关代码:
模板:
<script type="text/x-handlebars" data-template-name="container">
<button {{action "doSearch"}} rel="tooltip-bottom" title="search" class="icon"><i class="icofont-search"></i></button>
{{view Ember.TextField valueBinding="search" action="doSearch"}}
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="searchpage">
<h1>Search</h1>
{{#linkTo "home"}}Homepage{{/linkTo}}
<p>You searched for: "{{searchQuery}}"</p>
</script>
应用控制器:
MyApp.ApplicationController = Ember.Controller.extend({
// the initial value of the `search` property
search: '',
doSearch: function() {
// the current value of the text field
var query = this.get('search');
this.transitionToRoute('search');
}
});
和 Searchpage 路线:
MyApp.SearchRoute = Ember.Route.extend({
setupController: function(controller) {
controller.set('searchQuery', this.get('query'));
},
renderTemplate: function() {
this.render('searchpage', { into: 'container' });
}
});