我正在通过添加自定义模块来扩展 aurelia 的入门应用程序。读取 json 时出现错误“Uncaught SyntaxError: Unexpected token :”。但是 json 验证器没有发现任何错误。
这是我的json
{
"news": [
{
"title": "Lorem Ipsum is simply dummy text",
"type": "news",
"tags": [
"news",
"fish",
"loremipsumdolor"
],
"text": "Lorem Ipsum is simply dummy text of the printing and typesetting industry."
},
{
"title": "Lorem Ipsum",
"type": "news",
"tags": [
"news",
"fish"
],
"text": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s."
}
]
}
这是我尝试加载该 json 的模块(基本上它是来自 flickr.js 的复制粘贴,可以在示例代码中找到)` import {inject} from 'aurelia-framework'; 从'aurelia-http-client'导入{HttpClient};
@inject(HttpClient)
export class News{
heading = 'News';
items = [];
url = '/res/data.json';
constructor(http){
this.http = http;
}
activate(){
debugger;
return this.http.jsonp(this.url).then(response => {
this.items = response.content.news;
});
}
canDeactivate(){
return confirm('Are you sure you want to leave?');
}
}
' 执行示例代码时,它会从 flikr 加载 json 并将其包装在 jsonp_callback_92661() 中。这是唯一的区别。这可能是我问题的根源吗?