我有以下代碼,當輸入一個搜索查詢並按下輸入按鈕或單擊提交按鈕時調用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