2017-03-25 5 views
0

obv.mobx는 변수를 보지 않습니다

class App extends Component { 
     constructor(props){ 
     super(props); 
     } 
     render() { 
     const {socialJSX} = this.props.items?this.props.items.map((item)=> { 
      return <a className={"icon32-"+item.Title} href={item.Link.Url} target="_blank" title={item.Description} /> 
     }):""; 
     debugger 
     return (
      <div id="socialWrapper"> 
     <div id="socialWrap"> 
      {socialJSX} 
     </div> 
     </div> 
     ); 
     } 

     componentWillMount() { 
    fetch(`http://remoteurl`, { 
     method: 'GET', 
     headers: { 
     'Accept': 'application/json;', 
     'Content-Type': 'application/json' 
     }}).then((response) => { 
      return response.json(); 
      }) 
      .then((response) => { 
      $.each(response.value,(index, value)=>{ 
       if(value){ 
       this.props.appState.addItem({ 
        Title:value.Title, 
        Active:value.Active, 
        Description:value.Description, 
        Link:{Address:value.Link.Url, Description:value.Link.Description} 
       }); 
       } 
      }); 
      })= 
     } 
    } 

export default observer(App); 

하는 index.js : 여기

코드입니다 .. 내가 브라우저에서 HTML 출력하지만, 빈 페이지를 볼 것으로 예상 jsx 요소를 만드는 데 반복

const appState = new AppState(); 

ReactDOM.render(
    <App appState={appState} />, 
    document.getElementById('root') 
); 

AppState 서비스 .js

import { extendObservable, computed } from 'mobx'; 
class AppState { 
    constructor() { 
    extendObservable(this, { 
     items: [] 
    }); 
    } 
    addItem(item) { 
    debugger 
     this.items.push(item) 
    } 
} 
export default AppState 

항목에로드 된 콘텐츠 데이터를 확인했습니다. 여기에 무슨 문제가 있습니까?

답변

1

앱 구성 요소에 this.props.itemsthis.props.appState.items이어야합니다.

@action 
addItem(item) { 
    ... 
} 

또는

addItem = action(() => { 
    ... 
}); 
: 당신의 AppState 클래스 addItem에서

는 작업으로 정의되어야한다