我正在尝试传递两个数据值/以某种方式从复选框的onchange事件中检索两个值。
我有一个表行列表,每个tr上都有一个复选框。当您单击tr时,它应该将两个值传递给方法,以便我可以将这些值发送到其他地方。
这就是我一直试图做的:
getdataAttributes(attrName: string, attrPersonKey: string) {
this.empDataAttrObj.name = attrName;
this.empDataAttrObj.personKey = attrPersonKey;
this.tableRowDataService.send(this.empDataAttrObj);
}
<tr class="gridrow"
id="ngCheckRow"
#ngCheckRow
*ngFor="let employee of filteredEmployees"
attr.data-employment-name="{{employee.Name }}"
attr.data-employment-personkey="{{employee.PersonKey.CountryCode}}_{{employee.PersonKey._displayValue }}"
attr.data-employment-unitId="{{ unitId }}">
<td>
<input type="checkbox"
(change)="getdataAttributes({{employee.Name }}, {{employee.PersonKey.CountryCode}}_{{employee.PersonKey._displayValue }})">
</td>
我也尝试过($ event.target.value)。在控制台中,这仅给我字符串值“ on”。 如果我尝试($ event)它给了我dom,在这里我可以找到选中的tr(当您选中复选框时,它上面有一个“ .selected”类),也许我可以从那里获取值? (数据属性“名称”和“人员密钥”与我试图传递的属性相同)