Jquery 如何合并两个对象
我有两个目标Jquery 如何合并两个对象,jquery,svg,jquery-svg,Jquery,Svg,Jquery Svg,我有两个目标 var defPathValues={'id':'','fill':'','fill-opacity':'','stroke-width':'','stroke-linecap':'','stroke-linejoin':'', 'stroke':'','d':'','transform':''}; var options={'id':'ele1', 'fill':'white'}; 我希望合并这两个对象,并从defPathVal
var defPathValues={'id':'','fill':'','fill-opacity':'','stroke-width':'','stroke-linecap':'','stroke-linejoin':'',
'stroke':'','d':'','transform':''};
var options={'id':'ele1', 'fill':'white'};
我希望合并这两个对象,并从defPathValues中删除其他空属性(即基于我们传递的选项)
合并后,我想在svg路径元素中设置这些属性
在那之前我喜欢
var path = document.createElementNS(this.svgLink, "path");
$(path).attr({
'id': this.SvgObject.id+ "_" + series.Name + "_"+ seriesIndex,
'fill': 'none',
'stroke-width': style.SeriesStyle.BorderWidth,
'stroke': style.SeriesInterior,
'stroke-linecap': style.SeriesStyle.LineCap,
'stroke-linejoin':style.SeriesStyle.LineJoin,
'd': direction,
});
相反,我想直接将object设置为path元素的attr。如何做到这一点?这可能不是最优雅的解决方案,但我相信它会起作用:我假设您在代码运行之前已经将DefPathValue和选项定义为JS对象
for(var i in options) defPathValues[i] = options[i];
var newDefPathValues = {};
for(var i in defPathValues) {
if(typeof defPathValues[i] == 'undefined' || defPathValues[i] == '' || defPathValues[i] == null) continue;
newDefPathValues[i] = defPathValues[i];
}
defPathValues = newDefPathValues;