【发布时间】:2019-06-21 11:53:40
【问题描述】:
数据项已被标记为描述、已检查/未检查的布尔值、ID 等。
这是我的模板代码:
<StackLayout class="topbuttons">
<GridLayout columns="*,*" horizontalAlignment="left" verticalAlignment="top">
<Button class="btn btn-primary topbutton" text="Next" col="1" (tap)="onTap()"></Button>
</GridLayout>
更多
<GridLayout tkExampleTitle tkToggleNavButton class="topgrid" loaded="loaded" >
<RadListView [items]="dataItems" >
<ng-template tkListItemTemplate let-item="item">
<GridLayout class="garmentpick">
<Image [src]="item.image" (tap)="toggleCheck()" class="imageP" >
</Image>
<CheckBox #CB1 checked="false" text="{{ item.id }}" ></CheckBox>
</GridLayout>
</ng-template>
<ListViewGridLayout tkListViewLayout ios:itemHeight="200" spanCount="2"></ListViewGridLayout>
</RadListView>
打字稿
export const DATAITEMS: Array<DataItem> = [
{ id: 5451545,
name: "Chefs Collection",
description: "This is item description.",
image: "~/images/chefscollection.jpg",
selected: false
},
];
export class Component implements OnInit {
@ViewChild("CB1") firstCheckBox: ElementRef;
ngOnInit(): void {
this._dataItems = new ObservableArray(this.getDataItems());
}
getDataItems(): Array<DataItem> {
return DATAITEMS;
}
toggleCheck() {
console.log();
this.firstCheckBox.nativeElement.toggle();
}
onTap() {
const checkboxArray = new ObservableArray(this.items);
this._dataItems.forEach((item) => {
checkboxArray.push(this.firstCheckBox.nativeElement.text);
});
}
}
我想将点击的项目保存到一个数组中。我创建了一个数组,我将单击的项目推送到提交按钮的 ontap 中的数组,但是使用 Array.push(item.id) 只推送一个项目,或者在该数组中重复它。有什么办法可以做到这一点,我正在考虑数据表单
【问题讨论】:
标签: arrays angular checkbox nativescript