Kendo Checkbox切换True和False状态无法正常工作

发布于 2025-01-27 07:20:10 字数 744 浏览 3 评论 0原文

我正在尝试获取它,因此当单击一个或多个复选框时,我可以获取一个按钮。如果单击一个或多个复选框,我希望切换函数可以工作,但是,当我选择一个复选框时,它将打开,然后在下一次选择期间关闭。我敢肯定,我也在这里添加了几个不必要的属性,但对此不太担心。任何帮助将不胜感激。

HTML:按钮

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

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:按钮单击方法

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

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. 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

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

HTML: Checkbox Column

<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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

动听の歌 2025-02-03 07:20:10

将事件传递给您的函数,然后从打字稿类访问其值:
步骤1(通过$事件):
在 *ngfor标签级别添加索引var

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

step1(获取其值):

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

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

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

<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;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文