Javascript 反应-动态更改要取消选中的复选框
这张桌子上有这些复选框。 当我点击“添加条目”时,右模式被打开。 当我点击“完成”时,复选框将被取消选中,而不会刷新页面。 你能给我一个解决方案吗? 这是一个函数,它的内容是输入复选框Javascript 反应-动态更改要取消选中的复选框,javascript,reactjs,Javascript,Reactjs,这张桌子上有这些复选框。 当我点击“添加条目”时,右模式被打开。 当我点击“完成”时,复选框将被取消选中,而不会刷新页面。 你能给我一个解决方案吗? 这是一个函数,它的内容是输入复选框 chooseAppSelector=()=> { let appSelectorArray=[]; for (let application of this.state.appList) { appSelectorArray.pu
chooseAppSelector=()=>
{
let appSelectorArray=[];
for (let application of this.state.appList)
{
appSelectorArray.push(
<tr>
**<th scope="row"><input type="checkbox" className={"appsCheckbox"} id={"appSelectorCheckbox"+application.id} onClick={()=>this.checkCheckbox(application.id, application)}/></th>**
<td>{application.product}</td>
</tr>
)
}
return appSelectorArray;
}
checkboxStatus=()=> `this one is a validation of the checkbox clicks and it works as needed`
{
`I want to change the checkboxes status in here`
}
checkCheckbox=(appId, application)=>
{
let contains=this.selectedApps.includes(appId)
if (contains==false)
{
this.selectedApps.push(appId)
this.selectedAppsObjArr.push(application)
}
else
{
let index=this.selectedApps.indexOf(appId);
this.selectedApps.splice(index,1);
let index2=this.selectedAppsObjArr.indexOf(appId)
this.selectedAppsObjArr.splice(index2,1);
}
}
sendForm = () => {
this.toggleModal(); `Closing the Modal Window`
this.addNewNetworks() ` Not important function`
this.checkboxStatus(); `the above function`
}
render (){
return (
<Table striped bordered hover> `the table component`
<thead>
<tr>
<th>#</th>
<th>App</th>
</tr>
</thead>
<tbody>
chooseAppSelector=()=>
{
让appSelectorArray=[];
for(让应用程序使用this.state.appList)
{
appSelectorArray.push(
**this.checkCheckbox(application.id,application)}/>**
{application.product}
)
}
返回appSelectorArray;
}
checkboxStatus=()=>`这是对复选框单击的验证,它可以根据需要工作`
{
`我想更改此处的复选框状态`
}
复选框=(应用程序ID,应用程序)=>
{
let contains=this.selectedApps.includes(appId)
if(contains==false)
{
此.selectedApps.push(appId)
此.selectedAppsObjArr.push(应用程序)
}
其他的
{
设index=this.selectedApps.indexOf(appId);
此.选择的附加接头(索引,1);
设index2=this.selectedAppsObjArr.indexOf(appId)
该.选择的PPSOBJARR.拼接(index2,1);
}
}
sendForm=()=>{
this.toggleModal();`关闭模式窗口`
此.addNewNetworks()`函数不重要`
this.checkboxStatus();`上述函数`
}
渲染(){
返回(
`表组件`
#
应用程序
在“chooseAppSelector”中输入复选框
{this.chooseAppSelector()}
`divs`
)
提前感谢!!在完成的onClick处理程序中添加以下两行:
handleDone=()=>{
var clist=document.getElementsByClassName("appsCheckbox");
for (var i = 0; i < clist.length; ++i) { clist[i].checked = false }
}
handleDone=()=>{
var clist=document.getElementsByClassName(“appsCheckbox”);
对于(var i=0;i
将清除复选框的回调传递给模式。当用户单击“完成”时,在执行其他操作之前/之后调用回调。在checkboxStatus
函数中。返回事件并将其添加到复选框中,如下所示:
其中this.state.checked=false。然后在适当的时间调用它。
{this.chooseAppSelector()}
</tbody>
</Table>
`divs....`
)
handleDone=()=>{
var clist=document.getElementsByClassName("appsCheckbox");
for (var i = 0; i < clist.length; ++i) { clist[i].checked = false }
}