2016-05-01 17 views
1

我試圖更新二維數組的視圖,但視圖更新者更新新值。 如果我只有一個數組,它工作正常,但不是兩個。更新Aurelia中的二維數組的視圖

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()); 
      } 
     } 
    } 
}; 
+0

你能發表您的視圖代碼嗎? – kabaehr

回答

3

觀察索引賦值(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()); 
     } 
    } 
    } 
}