简体   繁体   English

通过使用其他文件来填充Javascript文件的数组

[英]Fill up array of a Javascript-File by using other file

I have a js-file(A) including an array 我有一个包含数组的js文件(A)

$(function(){
    function initVMap(){
        $('#vmap').vectorMap({
            map: 'world_mill',


     //...........................
            markers: [
                {latLng: [3.2, 73.22], name: 'Maldives'},
                {latLng: [35.88, 14.5], name: 'Malta'},
                {latLng: [12.05, -61.75], name: 'Grenada'},
                {latLng: [13.16, -59.55], name: 'Barbados'},
                {latLng: [17.11, -61.85], name: 'Antigua and Barbuda'},
                {latLng: [-4.61, 55.45], name: 'Seychelles'},
                {latLng: [7.35, 134.46], name: 'Palau'},                        
            ]
        });
    }

   //........................

the array data will be provided by another system and changes constantly. 阵列数据将由另一个系统提供并不断变化。 So, the idea is to provide array-data out of the other json-file(B). 因此,该想法是从另一个json-file(B)中提供数组数据。 My question is. 我的问题是。 Could somebody tell me if and how to call the other file(B) to fill up the array of my json-file(A)? 有人可以告诉我是否以及如何调用另一个文件(B)来填充我的json文件(A)的数组吗?

I probably have a solution. 我可能有解决方案。

I will write my array data to a json-file(FileB). 我将数组数据写入json-file(FileB)。 In my js-File(A) i will call the date in (FileB) like: 在我的js-File(A)中,我将在(FileB)中调用日期,例如:

var myList;
$.getJSON('json-file.json')
.done(function (data) {
myList = data;
});

But how to insert "myList" into my array of js-File(A)? 但是,如何将“ myList”插入到我的js-File(A)数组中?

markers: [
            {latLng: [3.2, 73.22], name: 'Maldives'},
            {latLng: [35.88, 14.5], name: 'Malta'},
            {latLng: [12.05, -61.75], name: 'Grenada'},
            {latLng: [13.16, -59.55], name: 'Barbados'},
            {latLng: [17.11, -61.85], name: 'Antigua and Barbuda'},
            {latLng: [-4.61, 55.45], name: 'Seychelles'},
            {latLng: [7.35, 134.46], name: 'Palau'},                        
        ]
    });
}

Can somebody help me? 有人可以帮我吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Javascript文件进行随机阻止? - Random Blocking with Javascript-File? 如何在 TYPO3 中的 JavaScript 文件中使用 Fluid (ViewHelper) 显示图片 - How to display a picture using Fluid (ViewHelper) from a JavaScript-file in TYPO3 包含另一个文件时,JavaScript文件停止工作 - JavaScript-file stopped working when including another file 在d3中单击按钮执行Javascript文件 - Execute Javascript-File with Button click in d3 从.tpl链接到外部Javascript文件不起作用 - Linking to external Javascript-file from .tpl does not work 在视图中强制重载Javascript文件而不发布服务器代码 - Force reload Javascript-file on publish WITHOUT server code in view 将包含外部 javascript 文件的外部 html 文件加载到 div - Loading an external html-file which includes an external javascript-file to a div 如何调用包含在 PHP 文件或 Javascript 文件中的“函数构造”? - How do I call a 'conscruct of functions' that are included in a PHP-file or a Javascript-file? 如何在引用的JavaScript文件中而不是之间使用Thymeleaf <script> tags - How to use Thymeleaf in a referenced JavaScript-File instead of between <script> tags 当文件夹的内容发生变化时,如何重新运行 Javascript 文件? - How do I re-run a Javascript-file when the content of a folder changes?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM