- 33
- 0
有一个父组件,在render中循环了N个子组件,每一个子组件上面都有一个唯一的ref,第一个子组件改变时,会回调父组件的change方法,在父组件中可以获得后一个组件,如this.refs['2nd'],现在想通过this.refs['2nd']改变组件数据,使得后一个组件进行更新。有没有相应的方法,促使后一个组件进行更新,因为无法更改后一个组件props,所以不知道怎么弄了。
所以就是,下拉框级联效果,用一个组件把级联的几个下拉框都做好关联,业务都写在这个组件里面,因为无法使用react常用的那种antd级联,只能这么做,有什么好的方法吗?
- 共 0 条
- 全部回答
-
世繁华 普通会员 1楼
在React中,this refers to the instance of the component that the component is a child of. In order to update the component, you need to call methods on the parent component that have access to the component's
thisreference.Here's an example of how you can use this to update a child component:
```jsx import React from 'react';
class ChildComponent extends React.Component { render() { return (
This is the child component.); } }class ParentComponent extends React.Component { constructor(props) { super(props); this.state = { count: 0 }; }
incrementCount() { this.setState({ count: this.state.count + 1 }); }
render() { return (
); } }export default ParentComponent; ```
In this example, the
ParentComponenthas a state variable calledcountthat is initially set to 0. TheincrementCountmethod increments thecountstate variable by 1. TheChildComponenthas a reference to theParentComponentusingthisrefs['ParentComponent'].When the user clicks the "Increment count" button, the
incrementCountmethod is called, which updates thecountstate variable and triggers the re-render of theChildComponent. This will cause the child component to update with the new value ofcount.
- 扫一扫访问手机版
回答动态

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器更新之后。服务器里面有部分玩家要重新创建角色是怎么回事啊?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题函数计算不同地域的是不能用内网吧?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题ARMS可以创建多个应用嘛?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题在ARMS如何申请加入公测呀?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题前端小程序接入这个arms具体是如何接入监控的,这个init方法在哪里进行添加?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器刚到期,是不是就不能再导出存档了呢?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器的游戏版本不兼容 尝试更新怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器服务器升级以后 就链接不上了,怎么办?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器转移以后服务器进不去了,怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器修改参数后游戏进入不了,是什么情况?预计能赚取 0积分收益
- 回到顶部
- 回到顶部

