/* *带有序列号的对象a,b * */ var a = { { nIndex: 0, name: "sdfhdrt", type: "B", len: 24 },{ nIndex: 1, name: "fgdfg", type: "B", len: 24 },{ nIndex: 2, name: "fgdfg", type: "B", len: 24 },{ nIndex: 3, name: "fgdfg", type: "B", len: 24 },{ nIndex: 4, name: "fgdfg", type: "B", len: 24 },{ nIndex: 5, name: "fgdfg", type: "B", len: 24 },{ nIndex: 6, name: "fgdfg", type: "B", len: 24 },{ nIndex: 7, name: "fgdfg", type: "B", len: 24 } } var b ={ { nIndex: 8, name: "fgdfg", type: "C", len: 12 },{ nIndex: 9, name: "fgdfg", type: "C", len: 12 },{ nIndex: 10, name: "fgdfg", type: "C", len: 12 },{ nIndex: 11, name: "fgdfg", type: "C", len: 12 } } //如何用JS将b添进a?序号接着
var globle= {};
Globle.nodges=[];
globle.edges=[];
结果就是
globle={nodges:[],
edges:[]}
{"nodges":[],"edges":[]}这种形式的其实叫json对象
JSON.parse(globle)就转成这种对象了
<!DOCTYPE html> <html> <body> <p id="demo">合并数组。</p> <button onclick="myFunction()">click me</button> <script> function myFunction() { //你可以把对象转换为数组 var hege = ["Cecilie", "Lone"]; var stale = ["Emil", "Tobias", "Linus"]; var children = hege.concat(stale); var x=document.getElementById("demo"); x.innerHTML=children;
//把数组再转换为对象 } </script> </body> </html>
美工出生的我认了,这种形式的不知怎么拼接了,我用d3.js库,里面的数据格式是:
/* * 一.d3.js插件自带的JSON数据结构,就两个数组 */ // 节点 var nodges = []; //节点组成的边 var edges = []; /* * 二. 现在根据实际后台Ajax得到的数据,欲拼接成如下形式(把两数组放进一对象): */ var GLOBEL = { "nodges":[], "edges":[] } /* * 三. 两个[]里有很对多数据{},定死不变的是:nodes[0]和*nodes[1]~nodes[8]组成7条连线,最终理想输出是: */ var GLOBAL = { "nodes" : [ { nIndex:0, name: 为数组labels[0], type: "R", len:100, basic: { 法定代表:"", 注册资本:"", 成立日期:"", 行业领域:"" } },{ nIndex:1, name: 为数组labels[1], type: "B", len:24 },{ nIndex:2, name: 为数组labels[2], type: "B", len:24, basic: { 法定代表:"", 注册资本:"", 成立日期:"", 行业领域:"" } },{ nIndex:3, name: 为数组labels[3], type: "B", len:24 },{ nIndex:4, name: 为数组labels[4], type: "B", len:24, basic: { 法定代表:"", 注册资本:"", 成立日期:"", 行业领域:"" } },{ nIndex:5, name: 为数组labels[5], type: "B", len:24, basic: { 法定代表:"", 注册资本:"", 成立日期:"", 行业领域:"" } },{ nIndex:6, name: 为数组labels[6], type: "B", len:24, basic: { 法定代表:"", 注册资本:"", 成立日期:"", 行业领域:"" } },{ nIndex:7, name: 为数组labels[7], type: "B", len:24 } ], "edges":[ { source:0, target:1 },{ source:0, target:2 },{ source:0, target:3 },{ source:0, target:4 },{ source:0, target:5 },{ source:0, target:6 },{ source:0, target:7 },{ source:0, target:8 } ] }; /* 定死的初始数据为:var labels = ["xxxx公司", "员工", "法院判决", "股东", "对外投资", "法院公告", "疑似关系", "高管"]; var labels_json = ["corpInfo", "corpEmployees", "corpCourtjudgment", "corpPartners", "invests", "courtAnnouncement", "relationship", "executive"]; 问题是:只有是公司类型有才有basic字段,(即labels_json[2],labels_json[4],labels_json[5],labels_json[6]),难点是:只有判断ajax数据:data.data.corpEmployees,data.data.corpCourtjudgment...有数据时候,按照nIndex顺序追加进nodes[],并且相应生成edges[],卡在这里了。 */
你这是什么玩意对象?var a = {{aa:1}},这语法都不正确了。如果是数组的话,直接concat就是了。