我有以下代码,当输入一个搜索查询并按下输入按钮或单击提交按钮时调用transitionToRoute('搜索')。EmberJS如何处理transitionTo
然而,我的网络仍然不会显示在模板中SEARCHQUERY那里说:
<p>You searched for: "{{searchQuery}}"</p>
和搜索东西的时候(这似乎不是我的权利的URL看起来像http://www.example.com/#/search/[object Object]
)。
(全码可浏览过: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' });
}
});
不是一个完整的答案,但您需要从应用程序控制器中检索您的搜索词,就像我的分叉小提琴一样:http://jsfiddle.net/DCrHG/2/ –
我想将其标记为答案,但我也想知道如何解决[object Object] URL – xorinzor