问题
Solving my previous question (ember-data error while loading route: TypeError {}) Turned up a new error, because I think this problem is not related to the previous question I decided to create a new question for it.
The error I'm getting now is:
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
(note: the double slash after "www.shoutzor.nl" is not creating an issue, the JSON response is still correct)
EDIT: It seems the problem is originating from one of these pieces of code because When I remove all Search-related code from the website it all works again (also I should note it does work when I visit a url like '/#/search/something' before anything else):
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();
and my 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>
回答1:
It seems the Map was causing the issue,
changing
this.route("search", { path: "/search" });
this.route("search", { path: "/search/:query" });
into
this.resource("search", { path: "/search" }, function() {
this.route(':query');
});
solved my problem
来源:https://stackoverflow.com/questions/19431300/ember-data-assertion-failed-cannot-call-get-with-query-on-an-undefined-object