离子2:如何向对象添加新项?

时间:2017-10-24 12:43:30

标签: javascript typescript ionic-framework

示例对象:

        this.advData = {
                        'title': this.addAdvS2.value.title ,
                        'breadcrumb': this.suggestData.breadcrumb,
                        'price': this.addAdvS2.value.price,
                        'status': this.addAdvS2.value.status,
                        'province': this.addAdvS2.value.province,
                        'city': this.addAdvS2.value.city,
                        'images': this.addAdvS2.value.images
                    };

我想将此项添加到“advData”对象:

{'id': this.suggestData.id}

我可以这样做,而不将对象转换为数组吗?

1 个答案:

答案 0 :(得分:1)

只需使用密钥添加它:

this.advData['id'] = this.suggestData.id