如何使用Nativescript在ListView中使用索引

时间:2019-07-18 12:22:03

标签: angular typescript listview nativescript

我对自己的代码有疑问:

我在项目中使用了ListView,代码如下:

rule NetworkAdminUser {
    description: "Grant business network administrators full access to user resources"
    participant: "org.hyperledger.composer.system.NetworkAdmin"
    operation: ALL
    resource: "**"
    action: ALLOW
}

rule NetworkAdminSystem {
    description: "Grant business network administrators full access to system resources"
    participant: "org.hyperledger.composer.system.NetworkAdmin"
    operation: ALL
    resource: "org.hyperledger.composer.system.**"
    action: ALLOW
}

Demo

我的问题是:如何使用索引?因此,当我单击按钮<ListView class="list-group" [items]="countries" (itemTap)="onItemTap($event)" style="height:1250px"> <ng-template let-country="item" let-i="index"> <FlexboxLayout flexDirection="row" class="list-group-item"> <Label [text]="country.name" class="list-group-item-heading" verticalAlignment="center" style="width: 60%"></Label> <Label [text]="country.price" class="list-group-item-heading" verticalAlignment="center" style="width: 60%"></Label> <Button (tap)="decrementQty($event)" text='-' style="width: 60%"> </Button> <TextField row="1" col="1" class="textfield" [text]="qty" editable="false" style="width: 60%"> </TextField> <Button (tap)="incrementQty($event)" text='+' style="width: 60%"> </Button> </FlexboxLayout> </ng-template> </ListView> 时,我只想增加一行而不是所有行的数量。为此,我在ng-table索引中声明,但没有函数。你能建议我任何解决方案吗?

2 个答案:

答案 0 :(得分:0)

尝试以下代码

<Button (tap)="incrementQty($event, i)" text='+' style="width: 60%">
</Button>

在js中使用以下内容

function incrementQty($event, i) {
   this.countries[i].qty++;
}

答案 1 :(得分:0)

我已经为您here更新了游乐场。您已经在页面级别定义了数量,这就是为什么在增加或减少数量时,它将被应用于所有行。 如果您想在每一行中使用数量,则它应该是dataprovider的一部分,例如

WITH Sales_CTE (SalesPersonID, NumberOfOrders)  
AS  
(  
    SELECT SalesPersonID, NumberOfOrders,ROW_NUMBER() OVER(PARTITION BY SalesPersonID)  NN
    FROM Sales.SalesOrderHeader  
)  
DELETE FROM Sales_CTE WHERE NN > 1

并且不断增加,像这样

countries: { name: string, product_id: string, price: number, qty: number }[] = [
        { name: "Australia", product_id: "1", price: 100, qty: 1 },
        { name: "Belgium", product_id: "2", price: 1009, qty: 1 },
        { name: "Bulgaria", product_id: "3", price: 1008, qty: 1 },
        { name: "Canada", product_id: "4", price: 1006, qty: 1 },
        { name: "Switzerland", product_id: "5", price: 1000, qty: 1 },
        { name: "China", product_id: "6", price: 1011, qty: 1 },
        { name: "Czech Republic", product_id: "7", price: 150, qty: 1 },
        { name: "Germany", product_id: "8", price: 109, qty: 1 },
        { name: "Spain", product_id: "9", price: 10, qty: 16 },
        { name: "Ethiopia", product_id: "10", price: 105, qty: 1 }
    ];