gpt4 book ai didi

javascript - react native : renderRow not executed

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:43:19 25 4
gpt4 key购买 nike

在下面的代码中,当 campaignsUpdated 调用 setState 时,render 会被记录到控制台,而不是 renderRow:

var React = require('react-native'),

Bus = require('../Bus'),
styles = require('../Styles'),
CampaignsStore = require('../stores/Campaigns'),
CampaignItem = require('./CampaignItem'),

{
Component,
Text,
TextInput,
ListView,
View,
NavigatorIOS,
ActivityIndicatorIOS
} = React


class CampaignList extends Component {
constructor(props) {
super(props)

this.state = {
dataSource: new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2})
}
}

componentDidMount() {
this.addListeners()
Bus.emit('campaigns:search', '')
}

componentWillUnmount() {
this.removeListeners()
}

render() {
console.log('render')
return (
<View style={styles.container}>
<TextInput
style={styles.searchInput}
placeholder='Campaign Name'
value={this.state.campaignName}
onChange={this.campaignSearchChanged.bind(this)}/>
<ListView
dataSource = {this.state.dataSource}
renderRow = {this.renderRow.bind(this)}/>
</View>
)
}

renderRow(campaign) {
console.log('renderRow')
return <CampaignItem campaign={campaign}/>
}

addListeners() {
Bus.on({
'campaigns:updated': this.campaignsUpdated.bind(this)
})
}

removeListeners() {
Bus.off({
'campaigns:updated': this.campaignsUpdated.bind(this)
})
}

campaignsUpdated(event) {
var campaigns = event.data
this.setState({
dataSource: this.state.dataSource.cloneWithRows(campaigns)
})
}

campaignSearchChanged(event) {
var campaignName = event.nativeEvent.text
Bus.emit('campaigns:search', campaignName)
}
}

module.exports = CampaignList

我在这里做错了什么?

最佳答案

您正在向 ListView 传递一个返回组件的函数 renderRow。一旦它通过,您将必须在 ListView 中调用该函数,大概是在 campaigns 的映射期间。

关于javascript - react native : renderRow not executed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29687885/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com