2017-03-07 169 views
0

我的代碼有什麼問題?找不到任何有意義的錯誤說明,停留20分鐘。無法渲染複選框

class HelloWidget extends React.Component { 
     constructor(props) { 
     super(props);   
     } 

     renderResult(data){ 

     return(
      data.fruits.map(obj => 
      <select> 
      <label>{obj.name}</label> 
      <input type="checkbox" defaultChecked={obj.value} /> 
      </select> 
      ) 
     ) 
     } 

     render() { 
     //assume data came from API 
     cosnt data = { 
      "fruits": [ 
      {"id":1,"name":"Durian","value":true}, 
      {"id":2,"name":"Banana","value":true}, 
      {"id":3,"name":"Mango","value":false} 
      ] 
     } 

     return (<div>{this.renderResult(data)}</div>) 
     } 
    } 

創建一個搗鼓調試https://jsfiddle.net/w9r6Lqvh/

回答

1

有在你的代碼的兩個小問題:

  1. 錯字:行28 cosnt - >const
  2. 除去空間:38號線< HelloWidget/> - >< HelloWidget />

更新提琴: https://jsfiddle.net/w9r6Lqvh/1/