angular - 从Angular中的数组获取数据拼接
问题描述
在这里,我试图从我的复选框值中获取值,并且我正在尝试无法拼接的唯一类型模板中的数据。
这是我的html代码
<div class="custom-control custom-checkbox" *ngFor="let data of Data; let i = index">
<input class="custom-control-input" type="checkbox" (click)="SelectedTemplates(check, $event,i)" [checked]="checked" [value]="data.id" id="{{data.appName}}">
<label class="custom-control-label" for="{{data.appName}}">{{data.templateName}} | {{data.appName}} |
{{data.docName}}</label>
</div>
这是我的 Typescript 函数在拼接时无法获取值
SelectedTemplates(check, event, index) {
if (event.target.checked === true) {
this.checkedItem = true;
this.NewArry.push({'partnerId': this.PartnerID, 'templateId': this.Data[index].id});
} else if (event.target.checked === false) {
for (let i = 0; i < this.NewArry.length; i++) {
this.checkedItem = false;
if (this.Data[index].id === this.NewArry[i]) {
console.log(this.NewArry[i].id);
this.NewArry.splice(i, 1);
}
}
}
this.AreaArr = this.NewArry;
}
解决方案
只需将此代码添加到您的 else if
this.NewArry.splice(index, 1);
推荐阅读
- c++ - 在 .text 部分定义只读数据的原因是什么?
- angular - Angular4 - 有没有办法使指令透明?
- javascript - 如何同时停止传播和允许模态?
- android - xamarin android 开始阻塞 GC eXPLICIT?
- python - 字符串作为关键字参数,并将 str.partition() 输出中的多个 dict 组合到一个 dict
- spring-boot - jhipster 登录页面未显示为 0auth 2.0
- selenium - 将存储字符串和硬写字符串与 If 语句进行比较
- tcpdf - tcpdf 的 imageSVG() 方法无法正确渲染 svg 文件
- reactjs - 在 react 和 electron 上通过“网站的安全证书”
- algorithm - 跳过已预订的时段并重新安排时段