解决我之前的问题(加载路由时出现余烬数据错误:TypeError {}) 出现了一个新错误,因为我认为这个问题与上一个问题无关,我决定为它创建一个新问题。
我现在得到的错误是:
XHR finished loading: "http://www.shoutzor.nl//api/emberstore/tracks/85/".
Assertion failed: Cannot call get with 'query' on an undefined object. ember.js:394
Uncaught TypeError: Cannot read property '__ember1382024509870_meta' of undefined
(注意:"www.shoutzor.nl"后面的双斜杠不会产生问题,JSON 响应仍然正确)
编辑:似乎问题源于这些代码片段之一,因为当我从网站中删除所有与搜索相关的代码时,它再次正常工作(我也应该注意,当我访问像"/#/search/something"这样的网址时,它确实有效)。
Shoutzor = Ember.Application.create();
Shoutzor.Router.map(function() {
//Home Page
this.route("home", { path: "/" });
//Track Page
this.route("track", { path: "/track/:id" });
//Search page
this.route("search", { path: "/search" });
this.route("search", { path: "/search/:query" });
});
Shoutzor.SearchRoute = Ember.Route.extend({
setupController: function(controller) {
controller.set('pageTitle', "Search");
},
renderTemplate: function() {
this.render('SearchPageContent', { outlet: 'pageContent', into: 'application' });
}
});
Shoutzor.ApplicationController = Ember.Controller.extend({
// the initial value of the `search` property
search: '',
actions: {
query: function() {
//the current value of the text field
var query = this.get('search');
this.transitionToRoute('search', { query: query });
}
}
});
Shoutzor.SearchController = Ember.Controller.extend();
和我的 HTML:
<script type="text/x-handlebars" data-template-name="SearchPageContent">
{literal}
<h1>Searching for: "{{search}}"</h1>
{{input type="text" value="search" action="query"}}
{/literal}
</script>
似乎是地图导致了这个问题,
改变
this.route("search", { path: "/search" });
this.route("search", { path: "/search/:query" });
到
this.resource("search", { path: "/search" }, function() {
this.route(':query');
});
解决了我的问题