0
您好我需要在listview中切換單個內容時,在nativescript angular中單擊相應按鈕時,我添加了下面的代碼。如果有人知道請回答我。在此先感謝用角度切換本地腳本中的listview內容
import { Component, OnInit } from "@angular/core";
import { Item } from "./item";
import { ItemService } from "./item.service";
@Component({
selector: "ns-items",
moduleId: module.id,
templateUrl: "./items.component.html",
})
export class ItemsComponent implements OnInit {
items: Item[];
isList = true;
toggle(){
this.isList = !this.isList;
}
constructor(private itemService: ItemService) { }
ngOnInit(): void {
this.items = this.itemService.getItems();
}
}
,在這裏我items.component.html
<ActionBar title="My App" class="action-bar">
</ActionBar>
<StackLayout class="page">
<ListView [items]="items" class="list-group">
<template let-item="item">
<GridLayout columns="auto,auto" width="210" height="210" >
<Label [text]="item.name" col="0"
class="list-group-item" visibility="{{isList ? 'visible' : 'collapse'}}"></Label>
<Button [text]="isList ? 'hide' : 'Show'" col="1" (tap)="toggle()"></Button>
</GridLayout>
</template>
</ListView>
</StackLayout>
這裏的問題是,當我點擊按鈕,所有的標籤切換。所以我需要動態生成變量。我很初學,所以任何人都可以幫助我? 提前致謝。
在認真做了一些修改,它的工作。謝謝 – Steve
我給出了這樣的樣子:'item.visible = false;'然後在html文件中'[visibility] =「item.visible?'collapse':'visible'」'根據我的要求 – Steve