HTML5 没有分开两个对象

HTML5 didn't separate two object

无法显示两个对象

this._formsServices.fetching(this._route.snapshot.paramMap.get('id')).subscribe(post => {
          this.field = this._formsServices.form;
          let comma: any;
          this.field.forEach(option => {
            if (option.optionEn) {
              this.options = []; <-----
              comma = option.optionEn.split(',');
              for (const key in comma) {
                if (comma.hasOwnProperty(key)) {
                    this.options.push({ label: comma[key], value: option.fieldType });
                }
              }
            }
          })
        });

输出控制台是正确的,但在 HTML5 没有显示这总是关注最后一个对象

(2) [{…}, {…}]
0: {label: "name1", value: "1"}
1: {label: "name1", value: "1"}
length: 2
__proto__: Array(0)
forms.component.ts:91 
(2) [{…}, {…}]
0: {label: "name2", value: "6"}
1: {label: "name2", value: "6"}

这是因为您正在擦除 this.options 每次循环中的数据。在第一个循环中,您将这两个值 0: {label: "name1", value: "1"} 1: {label: "name1", value: "1"} 推送到数组中,而在第二个循环中,您正在创建一个新数组 this.options = [];。删除此行,应该可以工作。