Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/452.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 向现有对象动态添加对象属性_Javascript_Angularjs_Highcharts - Fatal编程技术网

Javascript 向现有对象动态添加对象属性

Javascript 向现有对象动态添加对象属性,javascript,angularjs,highcharts,Javascript,Angularjs,Highcharts,所以我有一个json对象,比如: "highChart":{ "xAxis":{ "categories":[ "SYN 13 ", "Settlement", "Service Interaction", "FNOL", "Repair Process",

所以我有一个json对象,比如:

"highChart":{
            "xAxis":{  
               "categories":[  
                  "SYN 13 ",
                  "Settlement",
                  "Service Interaction",
                  "FNOL",
                  "Repair Process",
                  "Rental Experience",
                  "Appraisal",
                  "SYN 14 "
               ],
               "title":{  
                  "text":""
               },
               "labels":{  
                  "enabled":true,
                  "maxStaggerLines":1
               },
               "tickWidth":1
            }}
让我们将其定义为
$scope.chartConfig=highChart

现在我想向chartConfig添加另一个属性,如下所示:

"highChart":{
         "options":{
            "chart":{  
               "height":null,
               "type":"waterfall"
            }},
            "xAxis":{  
               "categories":[  
                  "SYN 13 ",
                  "Settlement",
                  "Service Interaction",
                  "FNOL",
                  "Repair Process",
                  "Rental Experience",
                  "Appraisal",
                  "SYN 14 "
               ],
               "title":{  
                  "text":""
               },
               "labels":{  
                  "enabled":true,
                  "maxStaggerLines":1
               },
               "tickWidth":1
            }}
因此,在初始化
$scope.chartConfig=highChart
之后,我想添加选项属性和图表属性,如上所示。我该怎么做?

就像这样

$scope.chartConfig.options = {
  "chart":{  
    "height":null,
    "type":"waterfall"
 }
};
就这样

$scope.chartConfig.options = {
  "chart":{  
    "height":null,
    "type":"waterfall"
 }
};

不是100%清楚你在问什么,但是你可以使用
angular.extend()
合并对象

var options = {
    "chart": {
        "height": null,
        "type": "waterfall"
    }
}

angular.extend($scope.chartConfig, options);

$scope.chartConfig
现在包含新属性。如果
选项
具有与原始值相同但不同的属性…原始值将使用这些值更新

不100%清楚您的要求,但您可以使用
angular.extend()
合并对象

var options = {
    "chart": {
        "height": null,
        "type": "waterfall"
    }
}

angular.extend($scope.chartConfig, options);
$scope.chartConfig
现在包含新属性。如果
options
具有与原始值相同但不同的属性…原始值将用这些值更新