简体   繁体   English

Kendo 复选框切换 true 和 false 状态不能正常工作

[英]Kendo checkbox toggle true and false states not working properly

I'm trying to get it so when one or more checkbox is clicked, I'm able to get a button to appear.我正在尝试获取它,以便在单击一个或多个复选框时,我能够显示一个按钮。 I would like the toggle function to work if one or more checkbox is clicked, but instead, it will turn on when I select one checkbox, then turn off during the next selection.如果单击一个或多个复选框,我希望切换 function 工作,但相反,当我 select 一个复选框时它会打开,然后在下一个选择期间关闭。 I'm sure I've got a couple of unnecessary properties added into here as well, but not too concerned about that.我确定我也在这里添加了一些不必要的属性,但我不太在意。 Any help would be appreciated.任何帮助,将不胜感激。

HTML: Button HTML:按钮

<button class="btn btn-primary"
*ngIf="switchCase" style="float:right"
>Save</button>

HTML: Checkbox Column HTML:复选框列

<kendo-grid-column field="checkbox" editor="boolean">
    <ng-template kendoGridCellTemplate let-dataItem id="flexSwitchCheckChecked"
    >
    <input type="checkbox" (click)="toggleButton(dataItem, 'checkbox' 
    [checked]="dataItem.checkbox"
    [width]="40"
      >

TS: Button click method TS: 按钮点击方法

public switchCase: boolean = false;
  toggleButton() {
    this.switchCase = !this.switchCase;

pass an event to your function then access its value from typescript class: Step1(pass an $event): on *ngFor tag level add an index var将一个事件传递给您的 function 然后从 typescript class 访问它的值: Step1(传递一个 $event):在 *ngFor 标签级别添加一个索引变量

<div *ngFor="let item of items;let i = index" >
    <input type="checkbox" (change)="toggleButton($event,i)">
</div>

Step1(get its value):第一步(获取其值):

      toggleButton($event,i) {
    let newValue = $event.target.value;
       // this.switchCase =newValue;

this.items[i].checked =  newValue;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM