我正在尝试使用Meteor读取JSON文件.我已经在stackoverflow上看到了各种答案,但似乎无法让它们工作.我试过这个 基本上说:
[{"id":1,"text":"foo"},{"id":2,"text":"bar"}]
Run Code Online (Sandbox Code Playgroud)
Meteor.startup(function() {
console.log(JSON.parse(Assets.getText('test.json')));
});
Run Code Online (Sandbox Code Playgroud)
然而,这个看似非常简单的示例不会将任何内容记录到控制台.如果我试着将它存储在一个变量而不是console.logging它然后显示它客户端我得到
Uncaught ReferenceError: myjson is not defined
Run Code Online (Sandbox Code Playgroud)
myjson是我存储它的变量.我试过阅读JSON客户端
Template.hello.events({
'click input': function () {
myjson = JSON.parse(Assets.getText("myfile.json"));
console.log("myjson")
});
}
Run Code Online (Sandbox Code Playgroud)
结果如下:
Uncaught ReferenceError: Assets is not defined
Run Code Online (Sandbox Code Playgroud)
希望有人可以帮助我
小智 3
服务器方法就可以了,去掉多余的分号(;)就可以了。您在客户通话中需要更多信息。JSON 数据来自回调。
在您的点击事件中使用它:
if (typeof console !== 'undefined'){
console.log("You're calling readit");
Meteor.call('readit',function(err,response){
console.log(response);
});
}
Run Code Online (Sandbox Code Playgroud)
流星!
归档时间: |
|
查看次数: |
7471 次 |
最近记录: |