调用函数时如何添加参数?
How to add the parameter when calling the function?
我正在尝试弄清楚如何调用具有参数的函数,我正在使用箭头函数。
举个例子:
_openAddDealer = (dealerInfo) => {
console.log(dealerInfo);
}
我需要通过按钮调用它
<FloatingActionButton onClick={this._openAddDealer}>
对于其余的功能,我不需要任何绑定到 this
或类似的东西。那么,我该怎么办呢:
<FloatingActionButton onClick={this._openAddDealer(dealerInfo)}>
我这样试过,但该函数是在应用程序加载时调用的,而不是在按下按钮时调用的。
可能就这么简单:
button.onClick = function() {
// with button's this
_openAddDealer.call(this, dealerInfo);
// with outside this
_openAddDealer(dealerInfo);
};
?我不知道你用 <
等做什么,所以我可能会误解...
我假设这是 JSX。您可能正在寻找类似的东西:
<FloatingActionButton onClick={() => this._openAddDealer(dealerInfo)}>
我正在尝试弄清楚如何调用具有参数的函数,我正在使用箭头函数。
举个例子:
_openAddDealer = (dealerInfo) => {
console.log(dealerInfo);
}
我需要通过按钮调用它
<FloatingActionButton onClick={this._openAddDealer}>
对于其余的功能,我不需要任何绑定到 this
或类似的东西。那么,我该怎么办呢:
<FloatingActionButton onClick={this._openAddDealer(dealerInfo)}>
我这样试过,但该函数是在应用程序加载时调用的,而不是在按下按钮时调用的。
可能就这么简单:
button.onClick = function() {
// with button's this
_openAddDealer.call(this, dealerInfo);
// with outside this
_openAddDealer(dealerInfo);
};
?我不知道你用 <
等做什么,所以我可能会误解...
我假设这是 JSX。您可能正在寻找类似的东西:
<FloatingActionButton onClick={() => this._openAddDealer(dealerInfo)}>