简体   繁体   English

我们可以使用复选框的 [checked] 属性的方法将其设置为 true/false

[英]Can we use a method on [checked] property of checkbox to set it to true/false

I want to set the [checked] property of the checkbox on a method call, but when I do that, the method is called but it doesn't change the status of the checkbox我想在方法调用时设置复选框的 [checked] 属性,但是当我这样做时,方法被调用但它不会改变复选框的状态

HTML HTML

<div*ngFor="let vest_style of VEST_STYLE">
    <input type="checkbox" value="{{vest_style._id}}" (change)="onCheckboxChange($event,i)" 
    [checked]="isCheckedFromOrder(vest_style._id)">&nbsp;{{vest_style.name}}
</div>

TS TS

isCheckedFromOrder(id) {
    this.styles.value.forEach(style => {
      console.log(style === id)
      return style === id
    })
  }

i know what the issue is.我知道问题是什么。 Instead of your code, use the following.使用以下代码代替您的代码。

let checked = false;
this.style.value.forEach(style => {
if (style == id) checked = true;
});
return checked;

暂无
暂无

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

相关问题 我们如何在html中分别为复选框处于选中或未选中状态的复选框的响应设置“ True”或“ False”字符串? - How do we set “True” or “False” strings to the response of a checkbox for its checked or unchecked state respectively in html? 每次我在边缘单击复选框选中的属性时,它都会设置为 true - checkbox checked property is set to true everytime I click on it on edge 在html5中将复选框设置为选中状态,我应该简单地使用checked(作为属性)还是checked=“checked”(作为属性)? - In html5 to set a checkbox as checked, should I simply use checked (as a property) or checked=“checked” ( as an attribute)? Rails:form_for 复选框设置为 true 或 false 是否选中/取消选中该框 - Rails: form_for checkbox set to true or false whether the box is checked/unchecked 如何在 HTML 表中用选中的复选框替换“TRUE”和用未选中的复选框替换“FALSE”? - How to replace "TRUE" with a checked checkbox and "FALSE" with a nonchecked checkbox in an HTML table? 该复选框在未选中时不能返回 False,但在选中时可以返回 True - The checkbox cannot return False when unchecked but can return True when checked 将复选框设置为检查值是否为真(.ascx) - Set checkbox to checked if value is true (.ascx) 选中时,为什么复选框属性显示为“ false”(未选中)? - Why do checkbox property show as 'false' (not checked) when checked? JQuery 输入类型 checkbox prop(&quot;checked&quot;, false/true) 做相反的事情 - JQuery input type checkbox prop("checked", false/true) does the opposite PHP联系表单,如果选中CheckBox,则在电子邮件中为True / False - PHP Contact form, True/False in Email if CheckBox is Checked
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM