如何在onValueChange等事件中放入两个函数?
我试过
onValueChange={(selected) => this.setState({selected}),this.state.eventOnChange}>
答案 0 :(得分:4)
怎么样:
using std::string;
// Returns a string by value
string s1() {
return "hello"; // This implicitly creates a std::string
}
// Also returns a string by value
string s2() {
string s = "how are you";
return s;
}
// Returns a pointer to a string - the caller is responsible for deleting
string* s3() {
string* s = new string;
*s = "this is a string";
return s;
}
// Does not work - do not use!
string* this_does_not_work() {
string s = "i am another string";
// Here we are returning a pointer to a locally allocated string.
// The string will be destroyed when this function returns, and the
// pointer will point at some random memory, not a string!
// Do not do this!
return &s;
}
int main() {
string v1 = s1();
// ...do things with v1...
string v2 = s2();
// ...do things with v2...
string* v3 = s3();
// ...do things with v3...
// We now own v3 and have to deallocate it!
delete v3;
}
答案 1 :(得分:2)
Component.setState()是异步的,可能会在第二次调用时锁定,但它仍在执行第一次调用。
在回调中执行第二次调用,如下所示:
onValueChange=
{ (selected) => {
this.setState(
{category:selected},() => {this.filter();} // Add Functions That's you want to call.
)
}
}
答案 2 :(得分:0)
解决了以下代码:
<TextInput
style={{height: 40, width: 200, borderColor: 'gray', borderWidth: 1, }}
onChangeText={(text) => this.setState({
text
}, () => {
this._onChangeText();
})
}
autoCorrect={false}
underlineColorAndroid='rgba(0,0,0,0)'
value={this.state.text}
/>
感谢@pinewood。
答案 3 :(得分:0)
onValueChange={(itemValue, itemIndex) => this.setState({id: itemValue}),this.getOtherFunction }