Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize two-level linkage with React

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article is to share with you how to achieve secondary linkage in React. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

The details are as follows

Realization effect: ordinary H6 page, I cut the picture and deleted the user part, but it does not affect the description.

The general idea is to transfer the data interface from the page to the component, and after the interaction is executed in the component, the selected data results are returned to the page through onTimeChange, and then displayed on the page.

I wrote it in Taro, and the grammar is the same as react.

Mini Program effect

A method from a long time ago, send you the implementation code:

1. There is a pop-up box module for selecting time on the page.

{this.state.isToggleOn & & ()}

2. In the bullet box

Import {Component} from "@ tarojs/taro"; import {View, Text} from "@ tarojs/components"; import SendTime from ".. / time"; import ". / index.scss"; export default class Panel extends Component {constructor (props) {super (props);} static defaultProps = {list: [], status: ""}; onClick () {this.props.onClick ();} onTimeChange (date, time) {this.props.onTimeChange (date, time) } render () {return ();}}

3. In the time component

Import {Component} from "@ tarojs/taro"; import {View, Text} from "@ tarojs/components"; import {imageList} from ".. / image"; import ". / index.scss"; let dateNum = 0, timeNum = 0 X default class SendTime extends Component {constructor (props) {super (props); this.state = {dateNum: dateNum, timeNum: timeNum, timeList: [],} } static defaultProps = {list: [],}; onClick () {this.props.onClick ();} switchDay (index, info) {this.setState ({dateNum: index,}); dateNum = index; this.switchTime (timeNum); let date = info? Info.date: ""; let time = info & & info.timeSegementList? Info.timeSegementList [0]: "; this.setState ({timeList: info.timeSegementList,}); this.onTimeChange (date, time);} switchTime (index) {let dateNum = this.state.dateNum; this.setState ({timeNum: index,}); timeNum = index; let date = this.props.list [dateNum]? This.props.list[ dateNum] .date: "; let time = this.props.list [dateNum]? This.props.list.timeSegementList [index]: ""; if (index! = 0) {this.onTimeChange (date, time);}} onTimeChange (date, time) {this.props.onTimeChange (date, time);} componentWillMount () {this.setState ({timeList: ["ship immediately after grouping"],}) } componentDidMount () {if (this.props.status) {this.switchDay (dateNum, this.props.list [dateNum]);} else {(dateNum = 0), (timeNum = 0); this.setState ({dataNum: 0, timeNum: 0,}, () = > {this.switchDay (0, this.props.list [0])) });} getClassName (index) {switch (index) {case this.state.dateNum: return "send-data-li current"; default: return "send-data-li" }} render () {return (delivery time {this.props.list.map ((info, index) = > ({info? Info.date: ""})} {this.state.timeList.map ((info, index) = > ({info}))}) Thank you for your reading! This is the end of this article on "how to achieve secondary linkage in React". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report