更新Aurelia中二维数组的视图

Update the view of a two dimensional array in Aurelia

本文关键字:视图 二维数组 Aurelia 更新      更新时间:2023-09-26

我正在尝试更新二维数组的视图,但视图神经会更新新值。如果我只有一个数组,它可以很好地工作,但不能与两个数组一起工作。

export class App {
    constructor(){
        this.numbers = [];
    };
    update(){
        for(var i=0; i < 5; i++){
            this.numbers[i] = [];
            for(var p=0; p < 4; p++){
                this.numbers[i].push(Math.random());
            }
        }
    }
};

观察索引赋值(myArray[x] = something)将需要脏检查。请改用myArray.splice(x, 0, something)

以下是使用视图模型的示例:https://gist.run?id=59e61de3899ded4225b54f44ac63ef8c

app.html

<template>
  <div repeat.for="y of numbers">
    <span repeat.for="x of y">${x}, </span>
  </div>
  <button click.delegate="update()">Update</button>
</template>

app.js

export class App {
  constructor(){
    this.numbers = [];
  }
  update(){
    for(var i=0; i < 5; i++){
     this.numbers.splice(i, 0, []);
      for(var p=0; p < 4; p++){
        this.numbers[i].push(Math.random());
      }
    }
  }
}