单击响应本机时禁用特定按钮

时间:2016-04-25 06:37:22

标签: listview reactjs react-native

我有ListView组件上列出的本机(大约3000个按钮)上的按钮列表。

如何在单击按钮时禁用按钮编号365?

1 个答案:

答案 0 :(得分:0)

您在此处未提及关键点,您打算如何禁用按钮?是否要禁用按钮以响应某些操作,或者您是否要默认禁用按钮?请明确说明。所以我在这里假设一些事情 -

  1. 您想要在某些操作时禁用按钮,您必须这样做 保持状态。
  2. 您使用过TouchableHighlightTouchableWithoutFeedback
  3. 智能地使用rowId来禁用确切的项目。填充一系列已撤消的ID,并相应地禁用该项。

    您的渲染方法呈现ListView

    render: function(){
        return(
            <ListView
                dataSource={this.state.dataSource}
                renderRow={(rowData, sectionID, rowID) => renderItem.bind(this, rowId)}
                style={styles.listView}
            />
        );
    },
    renderItem: function(id){
        return <Item id={id} enabled={this.state.isEnabled} data={{name: 'foo', details: 'bar'}} />
    }
    

    项目组件将拥有自己的功能,状态和道具。

    render: function(){
        return(
            <TouchableHighlight underlayColor={'#939393'} onPress={this.onPressItem}>
                <View style={styles.container}>
                    <Text>{this.props.data.name}</Text>
                    <Text>{this.props.data.details}</Text>
                </View>
            </TouchableHighlight>
        )
    },
    onPressItem: function(){
        if(this.props.enabled){
            //do something
        }
        else{
            //do nothing
        }
    }
    
相关问题