作者:泥泥的春天_565_576 | 来源:互联网 | 2023-05-18 23:46
Iamtryingtomakeasimplesamplepreviewerformyclientproject.Thelistofsamplesarestored
I am trying to make a simple sample previewer for my client project. The list of samples are stored in a JSON file. but the trouble is that I am not too familiar with using JSON, or programming itself, to be honest. I have written a short test code to see if this JSON file works well, but although I can access sampleData
variable from firebug console, the document.write(sampleData.length);
line seems to be unable to access sampleData
for some reason. The error shows:
我正在尝试为我的客户端项目制作一个简单的示例预览器。样本列表存储在JSON文件中。但问题是,我不太熟悉使用JSON或编程本身,说实话。我编写了一个简短的测试代码来查看这个JSON文件是否运行良好,但是我可以从firebug控制台访问sampleData变量,document.write(sampleData.length);由于某种原因,行似乎无法访问sampleData。错误显示:
TypeError: sampleData is undefined
TypeError:sampleData未定义
I suspect it has to do with variable scopes, but I am not sure.
我怀疑它与变量范围有关,但我不确定。
What should I do to make the sampleData
variable to work with the rest of the code?
I'm sorry I cannot disclose the contents of the json file. It contains an array of objects containing information of the products. it looks like
我该怎么做才能使sampleData变量与其余代码一起使用?对不起,我不能透露json文件的内容。它包含一系列包含产品信息的对象。看起来像
[
{
"aaa" : 000000;
},
{
"bbb" : 111111;
},
{
"ccc" : 222222;
}
]
It's a quite generic form of JSON file, as far as I can tell.
据我所知,它是一种非常通用的JSON文件形式。
5 个解决方案