简体   繁体   English

Ember JSON加载问题-加载路由时出错:未定义

[英]Ember JSON Loading Issue - Error while loading route: undefined

I have the following very simple file, but when I load it by going to the #/myitem path, in the console I get "Error while loading route: undefined". 我有以下非常简单的文件,但是当我通过转到#/ myitem路径进行加载时,在控制台中,我收到“加载路由时出错:未定义”。 The json file contents for testdata.json are shown in a comment at the top of the file. testdata.json的json文件内容显示在文件顶部的注释中。 I have validated through fiddler that the JSON file is coming down OK. 我已经通过提琴手验证了JSON文件是否正常。 Any help would be great! 任何帮助将是巨大的!

<head>
    <meta charset=utf-8 />
    <script src="js/libs/jquery-1.10.2.js"></script>
    <script src="js/libs/handlebars-v1.3.0.js"></script>
    <script src="js/libs/ember-1.4.0.js"></script>
    <script src="js/libs/ember-data.js"></script>
</head>

<body>

<!--
Here is what is in testdata.json:

[
    {  letter:"A", frequency:0.01492 },
    {  letter:"B", frequency:0.08167 }
]

-->

<script type="text/x-handlebars" id="application">
    <h1>Welcome to this Demo!!</h1>
    {{outlet}}
    <h1>Bye!!</h1>
            {{#link-to "myitem"}}My Item Route{{/link-to}}
</script>

<script type="text/x-handlebars" id="myitem">
    <h2>Some Items</h2>
    <ul>
        {{#each}}
        <li>{{letter}}</li>
        {{/each}}
    </ul>
</script>

<script language="JavaScript">

App = Ember.Application.create({
});

App.Router.map(function() {
    this.route('myitem');
});

App.MyitemRoute = Ember.Route.extend({
    model: function() {
        var data = Ember.$.getJSON('testdata.json');
        return data;
    }
});

</script>

</body>

This looks to be caused by testdata.json not containing valid json. 这似乎是由于testdata.json不包含有效的json引起的。

RFC 4627 states "a name is a string" meaning names need to be in quotes, whereas in your case letter and frequency aren't quoted. RFC 4627声明“名称是一个字符串”,这意味着名称必须用引号引起来,而在您的情况下, letterfrequency都不会用引号引起来。 I've had a quick go at reproducing this locally, and fixing up the quoting appears to resolve the issue. 我很快就在本地复制了此文件,并且修正了报价似乎可以解决此问题。 Try pasting this into testdata.json: 尝试将其粘贴到testdata.json中:

[ {"letter": "hello"}, {"letter": "world"} ]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 加载路径时,Ember数据错误:TypeError:未定义不是函数 - Ember data Error while loading route: TypeError: undefined is not a function Ember Data 1.0加载路径时出错:TypeError:无法设置未定义的属性&#39;typeKey&#39; - Ember Data 1.0 Error while loading route: TypeError: Cannot set property 'typeKey' of undefined 灰烬类型未定义,并且具有一对多关联的错误加载路线 - Ember type is undefined & error loading route with one-to-many association 灰烬多个Json请求加载路由时出错对象没有方法&#39;addArrayObserver&#39; - Ember multiple Json request Error while loading route Object has no method 'addArrayObserver' 加载路径时出现ember-data错误:TypeError {} - ember-data error while loading route: TypeError {} 灰烬附加RESTAdaptor:错误 <Ember.Route:ember325> /加载路径时出错,然后大量转储JavaScript - Ember attaching a RESTAdaptor: error on <Ember.Route:ember325> / Error while loading route followed by massive dump of JavaScript 加载路线时出错,无法读取未定义的属性 - error while loading route, cannot read property of undefined Ember:加载路径时出错:TypeError:对象函数...没有方法&#39;create&#39; - Ember: Error while loading route: TypeError: Object function… has no method 'create' EMBER-断言失败:加载路由时出错:TypeError:对象[object Object]没有方法&#39;addArrayObserver&#39; - EMBER— Assertion failed: Error while loading route: TypeError: Object [object Object] has no method 'addArrayObserver' 加载异步路由时出现Ember错误 - Ember error while loading asynchronous routes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM