[英]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声明“名称是一个字符串”,这意味着名称必须用引号引起来,而在您的情况下,
letter
和frequency
都不会用引号引起来。 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.