【发布时间】:2017-08-23 23:07:51
【问题描述】:
**Here is my code**
<td>
<label class="col-md-2">
<input type="checkbox" class="form-control" [ngModel]="row.create" name="create" [checked]="(row.create==='Y')" (change)="onChecked(operation, appName, 'create', $event.target.checked)">
</label>
<label class="col-md-2">
<input type="checkbox" class="form-control" [ngModel]="row.read" name="read" [checked]="(row.read==='Y')" (change)="onChecked(operation, appName, 'read', $event.target.checked)">
</label>
<label class="col-md-2">
<input type="checkbox" class="form-control" [ngModel]="row.exportFile" name="exportFile" [checked]="(row.exportFile==='Y')" (change)="onChecked(operation, appName, 'exportFile', $event.target.checked)">
</label>
<label class="col-md-2">
<input type="checkbox" class="form-control" [ngModel]="row.exportData" name="exportData" [checked]="(row.exportData==='Y')" (change)="onChecked(operation, appName, 'exportData', $event.target.checked)">
</label>
</td>
**Here is component.ts**
private onChecked(operation:any, appName: any, checked:boolean){
let appaccess = this.appData.find(
appaccess=>appaccess.appName===appName
);
let cbindex = this.appData.indexOf(appaccess);
if(checked){
switch(operation)
{
case 'create':
this.appData[cbindex].create = 'Y';
break;
case 'read':
this.appData[cbindex].read = 'Y';
break;
case 'exportFile':
this.appData[cbindex].exportFile = 'Y';
break;
case 'exportData':
this.appData[cbindex].exportData = 'Y';
break;
case 'publish':
this.appData[cbindex].publish = 'Y';
break;
}
console.log('option checked is '+ operation);
}
else{
switch(operation)
{
case 'create':
this.appData[cbindex].create = 'N';
break;
case 'read':
this.appData[cbindex].read = 'N';
break;
case 'exportFile':
this.appData[cbindex].exportFile = 'N';
break;
case 'exportData':
this.appData[cbindex].exportData = 'N';
break;
case 'publish':
this.appData[cbindex].publish = 'N';
break;
}
console.log('option unchecked is '+ operation);
}
}
我在数据库中有一些值为“是”和“否”的数据。当我选中需要发送是值时,当未选中时发送否。请为此编写任何函数。我还需要将相同的内容与数据库进行比较。请帮助我。提前致谢。
【问题讨论】:
-
你们有服务吗?如果是这样,只需使用来自 $event 的数据从 onChecked() 方法调用您的服务。检查这个答案:stackoverflow.com/questions/37077707/…如果您不熟悉服务 - 转到 Angular 教程:angular.io/docs/ts/latest/tutorial/toh-pt4.html
-
Stack Overflow不是免费的代码编写服务。您应该尝试自己编写代码。在doing more research 之后,如果您有问题,您可以发布您尝试过的内容,并清楚地解释什么不起作用并提供minimal reproducible example 。我建议阅读How to Ask 一个好问题和the perfect question。另外,请务必使用tour。
标签: angular typescript