将setNativeProps应用于FlatList中的InputText

时间:2018-09-03 14:38:30

标签: react-native

我需要在TouchableOpacity单击InputText时更改其内容,尝试使用以下代码,但返回“无法读取未定义的属性'setNativeProps'”。您知道如何解决此问题吗?

 clearText = (num,index) => {
        console.log(index)
        this.refs["img"+index].setNativeProps({text: num.toString()});
    };


    render() {
        return (
            <View style={styles.container}>
                <Image style={styles.logoHeader} source={require('../../public/images/productos.png')}/>
                <View style={styles.containerSearch}>
                    <TextInput
                        style={styles.inputBuscar}
                        placeholder={'Buscar Productos'}
                        underlineColorAndroid={"transparent"}
                    />
                    <Image style={styles.imageSearch} source={require('../../public/images/search.png')}/>
                </View>


                <View style={styles.containerPro}>
                    <List containerStyle={{borderTopWidth: 0, borderBottomWidth: 0}}
                          key={this.state.coins.length}>
                        <FlatList
                            data={this.state.coins}
                            keyExtractor={(item) => item.id.toString()}
                            refreshControl={
                                <RefreshControl
                                    refreshing={this.state.refreshing}
                                    onRefresh={this._onRefresh}
                                />
                            }
                            renderItem={({item, index}) => {

                                let num = 0;


                                this.state = {
                                    numb: num,
                                };



                                let url = 'http://laeconomiadelsur.com/upload/' + item.foto;
                                const tableData = [
                                    [<View>
                                        <Image source={{uri: url}} style={{
                                            width: 50,
                                            height: 70,
                                        }}/>
                                    </View>,
                                    ],
                                    [<View style={styles.cellIcons}>
                                        <Text
                                            style={styles.textCells}>{item.nombre}</Text>
                                        <Text
                                            style={styles.textCellsDescription}>{item.descripcion}</Text>
                                        <Text
                                            style={styles.textCellsPrecio}>${item.precio.toLocaleString()}</Text>
                                    </View>,

                                    ],
                                    [<View>
                                        <Text style={styles.cantidad1}>subtotal: <Text>$300000</Text></Text>
                                        <View style={styles.buttonsAdd}>
                                            <TouchableOpacity
                                                style={styles.button1}
                                                navigation={this.props.navigation}
                                                onPress={() => {
                                                    this.setState({
                                                        numberText: this.state.numberText - 1
                                                    })
                                                }}
                                            >
                                                <Text>-</Text>
                                            </TouchableOpacity>
                                            <TextInput
                                                style={styles.textSum}
                                                placeholder="0"
                                                underlineColorAndroid={"transparent"}
                                                ref={"img"+ index}

                                            />
                                            <TouchableOpacity
                                                style={styles.button2}
                                                navigation={this.props.navigation}
                                                onPress={() => {
                                                    num = num + 1;
                                                    this.clearText(num,index);
                                                    console.log(num)
                                                }}
                                            >
                                                <Text>+</Text>
                                            </TouchableOpacity>
                                        </View>
                                        <Text style={styles.cantidad}>cantidad</Text>
                                    </View>,]
                                ];

                                return (
                                    <View style={{flex: 1}} key={item.id}>
                                        <Table style={styles.table} borderStyle={{borderWidth: 2, borderColor: 'white'}}
                                               key={item.id}>
                                            <Cols data={tableData} flexArr={[1, 2, 2]} style={styles.cells}
                                                  key={item.id}/>
                                        </Table>
                                    </View>
                                );
                            }}
                        />
                    </List>
                </View>


            </View>
        );
    }

我期望的行为是通过按下“ +”按钮,TextInput中的数量被更改enter image description here

0 个答案:

没有答案