我想在作为对象fwnodes
数组一部分的数组末尾添加新值。 firstNodeKey
是fwnodes
内部的数组。
我在fwnodes
下面给出了一些对象。现在,我想填充firstNodeKey
数组一个将根据条件选择的对象。
var fwnodes = [{
key: "10.0.0.1",
label: "10.0.0.1",
shape: $scope.vis.params.shapeFirstNode,
color: $scope.vis.params.firstNodeColor,
firstNodeKey: [],
secondNodeKey: []
},
{
key: "10.1.0.1",
label: "10.1.0.1",
shape: $scope.vis.params.shapeFirstNode,
color: $scope.vis.params.firstNodeColor,
firstNodeKey: [],
secondNodeKey: []
},
{
key: "10.2.0.0",
label: "10.2.0.0",
shape: $scope.vis.params.shapeFirstNode,
color: $scope.vis.params.firstNodeColor,
firstNodeKey: [],
secondNodeKey: []
},
{
key: "10.201.0.2",
label: "10.201.0.2",
shape: $scope.vis.params.shapeFirstNode,
color: $scope.vis.params.firstNodeColor,
firstNodeKey: [],
secondNodeKey: []
},
{
key: "10.50.0.1",
label: "10.50.0.1",
shape: $scope.vis.params.shapeFirstNode,
color: $scope.vis.params.firstNodeColor,
firstNodeKey: [],
secondNodeKey: []
},
{
key: "10.30.0.2",
label: "10.30.0.2",
shape: $scope.vis.params.shapeFirstNode,
color: $scope.vis.params.firstNodeColor,
firstNodeKey: [],
secondNodeKey: []
},
{
key: "10.20.0.1",
label: "10.20.0.1",
shape: $scope.vis.params.shapeFirstNode,
color: $scope.vis.params.firstNodeColor,
firstNodeKey: [],
secondNodeKey: []
}]
预期结果:
var fwnodes = [{
key: "10.0.0.1",
label: "10.0.0.1",
shape: $scope.vis.params.shapeFirstNode,
color: $scope.vis.params.firstNodeColor,
firstNodeKey: ["10.0.0.34", "10.0.0.24", "10.0.0.76"],
secondNodeKey: []
},
{
key: "10.1.0.1",
label: "10.1.0.1",
shape: $scope.vis.params.shapeFirstNode,
color: $scope.vis.params.firstNodeColor,
firstNodeKey: ["10.1.0.30", "10.1.0.45"],
secondNodeKey: []
},
{
key: "10.2.0.0",
label: "10.2.0.0",
shape: $scope.vis.params.shapeFirstNode,
color: $scope.vis.params.firstNodeColor,
firstNodeKey: [],
secondNodeKey: []
},
{
key: "10.201.0.2",
label: "10.201.0.2",
shape: $scope.vis.params.shapeFirstNode,
color: $scope.vis.params.firstNodeColor,
firstNodeKey: [],
secondNodeKey: []
},
{
key: "10.50.0.1",
label: "10.50.0.1",
shape: $scope.vis.params.shapeFirstNode,
color: $scope.vis.params.firstNodeColor,
firstNodeKey: [],
secondNodeKey: []
},
{
key: "10.30.0.2",
label: "10.30.0.2",
shape: $scope.vis.params.shapeFirstNode,
color: $scope.vis.params.firstNodeColor,
firstNodeKey: [],
secondNodeKey: []
},
{
key: "10.20.0.1",
label: "10.20.0.1",
shape: $scope.vis.params.shapeFirstNode,
color: $scope.vis.params.firstNodeColor,
firstNodeKey: [],
secondNodeKey: []
}]