ember-data断言失败:无法在未定义的对象上使用“查询”调用get [英] ember-data Assertion failed: Cannot call get with 'query' on an undefined object

查看:116
本文介绍了ember-data断言失败:无法在未定义的对象上使用“查询”调用get的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决我的上一个问题(加载路线时出现ember-data错误:TypeError { } )出现了一个新错误,因为我认为这个问题与我决定为其创建一个新问题的上一个问题无关。

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.

我现在得到的错误是:

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响应仍然正确)

(note: the double slash after "www.shoutzor.nl" is not creating an issue, the JSON response is still correct)

编辑:看来问题出在这些代码之一,因为当我从网站上删除所有与搜索相关的代码时,所有代码又都可以工作了(另外我应该注意,当我访问'/#/ search / something之类的网址时,它确实可以工作'。)

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();

和我的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>


推荐答案

似乎是地图引起了问题,

It seems the Map was causing the issue,

更改

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

进入

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

解决了我的问题

这篇关于ember-data断言失败:无法在未定义的对象上使用“查询”调用get的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆