2013-04-16 2 views
0

를 병합하는 방법을 나는 두 물체두 개체

나는이 두 개체를 병합 defPathValues에서 다른 빈 속성을 제거 할
var defPathValues={'id':'','fill':'','fill-opacity':'','stroke-width':'','stroke-linecap':'','stroke-linejoin':'', 
         'stroke':'','d':'','transform':''}; 

var options={'id':'ele1', 'fill':'white'}; 

이 (즉, 우리가 통과 옵션에 따라).

병합 후 svg path 요소에서 이러한 속성을 설정하고 싶습니다.

는 그 전에 내가 대신 경로 요소의 ATTR에 직접 객체를 설정하려는 그

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, 

     }); 

같은 데. 내가 어떻게 할 수 있니?

답변

0

이것은 가장 우아한 해결책은 아니지만 작동 할 것이라고 확신합니다. 이전에이 코드가 실행되기 전에 defPathValues ​​및 옵션을 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;