小编usm*_*ana的帖子

如何定义键值对的Typescript Map.其中key是数字,value是对象数组

在我的angular2应用程序中,我想创建一个以数字为键并返回一个对象数组的地图.我目前正在以下列方式实施,但没有运气.我应该如何实现它,还是应该为此目的使用其他数据结构?我想使用地图,因为它可能很快?

宣言

 private myarray : [{productId : number , price : number , discount : number}];

priceListMap : Map<number, [{productId : number , price : number , discount : number}]> 
= new Map<number, [{productId : number , price : number , discount : number}]>();
Run Code Online (Sandbox Code Playgroud)

用法

this.myarray.push({productId : 1 , price : 100 , discount : 10});
this.myarray.push({productId : 2 , price : 200 , discount : 20});
this.myarray.push({productId : 3 , price : 300 , discount : 30});
this.priceListMap.set(1 , …
Run Code Online (Sandbox Code Playgroud)

arrays json typescript angular

38
推荐指数
3
解决办法
12万
查看次数

Angular2-删除后更新UI

我有一个angular2应用程序,其后端是在java中.我有一份客户名单.当我单击以删除客户时,客户将被删除,但列表不会更新.如果我手动刷新页面,则列表会更新.我尝试在delete方法的订阅中路由到列表组件,但这不起作用.

列表customers.component.html

<tr [class.warning]="customer.isDefault == 1" *ngFor="let customer of customers | orderBy:['firstName'] | search:searchCustomer.value;let serial = index">
                <td>{{ serial+1 }}</td>
                <td>{{ customer?.firstName+' '+customer?.lastName}}</td>
                <td>{{ customer.email}}</td>
                <td>{{ customer.mobileNumber}}</td>
                <td>{{ customer.streetAddress}}</td>
                <td>{{ customer.priceList?.name}}</td>
                <td><a [routerLink]="['/loggedIn','customer','edit', customer.id ]"><i class="fa fa-edit fa-2x"></i></a></td>
                <td><a (click)="delete(customer)"><i class="fa fa-trash-o fa-2x"></i></a></td>
              </tr>
Run Code Online (Sandbox Code Playgroud)

列表customers.component.ts

    ngOnInit()
    {
        this.refreshCustomersList();
    }

    delete(customer)
    {
        this.userService.delete(customer.id)
            .subscribe(
                success=>
                {
                    var index = this.customers.indexOf(customer, 0);
                    if (index > -1)
                    {
                        this.customers.splice(index, 1);
                    }
                }
            )

    }

    refreshCustomersList()
    {
        this._authHttp.get(
                this.appService.getApiUrl() + "api/customer/list"
            )
            .map(res=>res.json())
            .subscribe( …
Run Code Online (Sandbox Code Playgroud)

typescript angular2-template angular2-routing angular

4
推荐指数
1
解决办法
1万
查看次数