2015-05-08 17 views
0

在javascript中,我定義了一些內嵌式樣,其中一個是字體重量。不幸的是,它不工作,因爲自動'px'被添加到值的末尾,然後它不會呈現爲值不正確:像素被添加到內聯字體重量

注意:我正在使用react,因此代碼看起來像如下所示。

render: function() { 
    return (
     <table> 
      <tbody> 
       <tr> 
        { 
         data.map(function(d, i) { 
          var style = {}; 
          if (d.value === 'selected') { 
           style['color'] = '#FFFFFF'; 
           style['font-size'] = '16px'; 
           style['font-style'] = 'normal'; 
           style['font-weight'] = '700'; 
           style['text-transform'] = 'uppercase'; 
          }else { 
           style['border'] = '2px solid #C9C9C9'; 
           style['color'] = '#C9C9C9'; 
           style['font-size'] = '12px'; 
           style['font-style'] = 'normal'; 
           style['font-weight'] = '400'; 
          } 
          return (<td> 
           <div style={style}> 
            {d.value} 
           </div> 
          </td>); 
         }) 
         } 
       </tr> 
      </tbody> 
     </table> 
    ); 
} 

當我在Chrome檢查它,它表明:font-weight: 700px和它不工作作爲px使得值不正確。

回答

2

嘗試使用style['fontWeight']而不是style['font-weight']根據反應文檔here fontWeight屬性將不會獲得自動'px'後綴。