我有一个很大的JavaScript对象文字,我每次都会重复使用很少的修改.最好创建一个包含大部分对象的变量,然后在每次需要时引用它.
但是我该怎么做呢?我试图这样做,但它不起作用:
var settings = {
legend: {
enabled:false
},
yAxis: {
title: {
text: 'Impact'
}
},
tooltip: {
formatter: function() {
return 'Impact: '+ this.y +' points'
}
},
credits: {
enabled: false
},
exporting: {
enabled: false
}
};
jQuery(document).ready(function() {
new Highcharts.Chart({
chart: {
renderTo: 'chart',
defaultSeriesType: 'column',
width: 450
},
title: {
text: 'Comparison of Impact for Male age 23'
},
xAxis: {
categories: [
'Good brain',
'Good humor',
'Good will'
],
},
series: [{
data: [5,2,8]
}],
settings // <-- HERE
});
});
Run Code Online (Sandbox Code Playgroud)
jQuerys .extend() 方法就是你要找的.
例如
$.extend(true, settings, {
yAxis: {
title: {
text: 'Impact NEW'
}
}
});
Run Code Online (Sandbox Code Playgroud)
只需更换yAxis你的部分settings object
参考:.extend()
| 归档时间: |
|
| 查看次数: |
2894 次 |
| 最近记录: |