Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Reactjs:当出现新道具时,如何更新组件?_Javascript_Reactjs - Fatal编程技术网

Javascript Reactjs:当出现新道具时,如何更新组件?

Javascript Reactjs:当出现新道具时,如何更新组件?,javascript,reactjs,Javascript,Reactjs,我想在出现新更新后更新/重新渲染组件。我所做的就是: 我有一个赌场游戏的庄家列表,我想添加一个新的庄家,一旦添加了新的庄家,然后在视图中显示它。它实际上正在发生,但为了让我看到新的经销商,我必须重新加载页面 我没有更新状态,我正在使用这个.props。看看我的代码 @connectToStores export default class Dealers extends Component { constructor (props) { super(props); this

我想在出现新更新后更新/重新渲染组件。我所做的就是:

我有一个赌场游戏的庄家列表,我想添加一个新的庄家,一旦添加了新的庄家,然后在视图中显示它。它实际上正在发生,但为了让我看到新的经销商,我必须重新加载页面

我没有更新状态,我正在使用
这个.props
。看看我的代码

@connectToStores
export default class Dealers extends Component {

  constructor (props) {
    super(props);
    this.state = {}
  }

  componentWillMount () {
    GetDealersActions.getDealers();
  }

  static getStores () {
    return [ GetDealersStore, CreateDealersStore ];
  }

  static getPropsFromStores () {
    return {
      ...GetDealersStore.getState(),
      ...CreateDealersStore.getState(),
    }
  }

  render () {
    return (
      <div>
         {!!this.props.dealerData ?
           this.props.dealerData.dealersData.map((dealer) => {
             return (here I am rendering what I need);
          : <p>Loading . . .</p>
      </div>
  }

  _addDealer = () => {
    CreateDealersActions.createDealer({
      DealerName : this.refs.DealerName.getValue(),
      CardId     : this.refs.CardId.getValue(),
      NickName   : this.refs.NickName.getValue(),
    });
  }
}
商店

@createStore(flux)
class CreateDealersStore {

  constructor () {
    this.state = {
      newDealerData : null,
    };
  }

  @bind(CreateDealersActions.createDealerSuccess)
  createDealerSuccess (data) {
    this.setState({
      newDealerData : data.response.config.data,
    });
  }

}
经销商组件位于名为
管理
的选项卡内,即此选项卡:

const menuItems = [
  { route : 'dealers', text : 'Dealers' },
  { route : 'game-info', text : 'Game Info' },
  { route : 'player-info', text : 'Players Info' },
  { route : 'money', text : 'Money' }
];

export default class Management extends React.Component {

  static propTypes = {
    getActivePage : React.PropTypes.func,
    menuItems : React.PropTypes.arrayOf(React.PropTypes.object),
  }

  static contextTypes = {
    router : React.PropTypes.func,
  }

  render () {
    return (
      <div>
        <TabsMainMenu menuItems={menuItems} getActivePage={this._getActivePage} />
        <RouteHandler />
      </div>
    );
  }

  _getActivePage = () => {
    for (const i in menuItems) {
      if (this.context.router.isActive(menuItems[i].route)) return parseInt(i, 10);
    }
  }
}
const menuItems=[
{路线:'经销商',文字:'经销商'},
{路线:'游戏信息',文字:'游戏信息'},
{路线:“玩家信息”,文本:“玩家信息”},
{路线:'money',文字:'money'}
];
导出默认类管理扩展React.Component{
静态类型={
getActivePage:React.PropTypes.func,
menuItems:React.PropTypes.arrayOf(React.PropTypes.object),
}
静态上下文类型={
路由器:React.PropTypes.func,
}
渲染(){
返回(
);
}
_getActivePage=()=>{
用于(菜单项中的常量i){
if(this.context.router.isActive(menuItems[i].route))返回parseInt(i,10);
}
}
}

您使用的是哪个flux框架?您能展示经销商的父组件吗?@E_net4查看更新在这种情况下,我将使用shouldComponentUpdate方法,它需要下一个道具和下一个状态,您可以比较它们//@您能给我一个小的代码示例吗?我在网上什么也没看到。对不起,我只是一个初级开发人员。你在使用哪个flux框架?你能展示
经销商的父组件吗?@E_net4查看更新在这种情况下,我将使用shouldComponentUpdate方法,它需要下一个道具和下一个状态,你可以比较它们///你能给我一个小的代码示例吗?我在网上什么也没看到。对不起,我只是个小德夫。
const menuItems = [
  { route : 'dealers', text : 'Dealers' },
  { route : 'game-info', text : 'Game Info' },
  { route : 'player-info', text : 'Players Info' },
  { route : 'money', text : 'Money' }
];

export default class Management extends React.Component {

  static propTypes = {
    getActivePage : React.PropTypes.func,
    menuItems : React.PropTypes.arrayOf(React.PropTypes.object),
  }

  static contextTypes = {
    router : React.PropTypes.func,
  }

  render () {
    return (
      <div>
        <TabsMainMenu menuItems={menuItems} getActivePage={this._getActivePage} />
        <RouteHandler />
      </div>
    );
  }

  _getActivePage = () => {
    for (const i in menuItems) {
      if (this.context.router.isActive(menuItems[i].route)) return parseInt(i, 10);
    }
  }
}