2017-03-25 12 views
0

私はobvの配列の値を設定します。ここmobxは変数を見ないでください

..私は、ブラウザでこのHTML出力が、空白のページを参照してくださいすることが期待JSX要素を作成するために、それを反復処理するコードです:

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:

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

はアクションとして定義されるべきです

関連する問題