我可以从下拉选择变量中删除 'null'
Can I remove 'null' from my drop down selection variable
我有一个多 select 下拉列表,允许我的用户使用 react-select select 多个 A、B and/or C 选项。每次 selected,我希望将其添加到 'choice' 变量中以保持记录。我有这个工作,但由于我必须先声明我的变量,它在变量中保存 'null' 。我该如何摆脱这个?下面的代码。
handleChange = (selectedChoice) => {
this.setState({ selectedChoice });
for (var i =0; i < selectedChoice.length; i++) {
var filter = null;
filter +=(selectedChoice[i].value); //removing the plus just resets it to last chosen option
}
console.log(filter);
}
打印内容示例:nullAC
此问题的解决方案由 Yury Tarabanko 在评论中发布。
var filter = ''
为了良好实践,console.log 也不会位于代码中的那个位置。
我有一个多 select 下拉列表,允许我的用户使用 react-select select 多个 A、B and/or C 选项。每次 selected,我希望将其添加到 'choice' 变量中以保持记录。我有这个工作,但由于我必须先声明我的变量,它在变量中保存 'null' 。我该如何摆脱这个?下面的代码。
handleChange = (selectedChoice) => {
this.setState({ selectedChoice });
for (var i =0; i < selectedChoice.length; i++) {
var filter = null;
filter +=(selectedChoice[i].value); //removing the plus just resets it to last chosen option
}
console.log(filter);
}
打印内容示例:nullAC
此问题的解决方案由 Yury Tarabanko 在评论中发布。
var filter = ''
为了良好实践,console.log 也不会位于代码中的那个位置。