ember-data断言失败:无法在未定义的对象上使用'query'调用get

时间:2013-10-17 15:44:07

标签: javascript ember.js ember-data

解决我之前的问题(ember-data error while loading route: 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>

1 个答案:

答案 0 :(得分:1)

地图似乎导致了这个问题,

改变

this.route("search", { path: "/search" });
this.route("search", { path: "/search/:query" });

this.resource("search", { path: "/search" }, function() {
    this.route(':query');
});

解决了我的问题