我将此网站的内容复制到我的解决方案中的 App/data/names.js
目录中的文件:https://raw.githubusercontent.com/dominictarr/random-name/master/names.json
我这样做是因为数组太大,无法放入我编写代码并显式初始化变量的文件中。但我仍然想将它分配给我创建的变量。我有这样的想法。
var arrayOfNames = readJSonFromFile("path");
可以实现吗?
最佳答案
像这样!
$.getJSON('path', function (arrayOfNames) {
// do things with your arrayOfNames
} );
关于javascript - 如何从另一个文件读取数组数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40105208/