Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.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
Jquery 如何合并两个对象_Jquery_Svg_Jquery Svg - Fatal编程技术网

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;