更新数组并更改视图,AureliaJS

时间:2016-10-29 07:26:49

标签: aurelia

刚进入AureliaJS,非常有趣的框架 我试图实施一个简单的tic tac toe游戏,但我无法弄清楚我做错了什么。

App.js:

export class App {
    constructor() {
        this.heading = 'Tic-Tac-Toe';
        this.board = ["", "", "", "", "", "", "", "", ""];
        this.playerOne = 'X';
        this.playerTwo = 'O';
        this.currentPlayer = this.playerOne;
    }

    makeTurn(index) {
        if(this.board[index] === "") {
            this.board[index] = this.currentPlayer;
            this.currentPlayer = this.currentPlayer === this.playerOne ? this.playerTwo : this.playerOne;
            console.log(this.board);
        }
    }
}

App.html:

<template>
    <require from="style.css"></require>
    <h1>${heading}</h1>

    <div class="board">
        <div repeat.for="sqare of board" class="sqare" click.trigger="makeTurn({$index}.$index)">${sqare}</div>
    </div>
</template>

如果我尝试更改makeTurn函数中的标题变量,它会更改标题,因此我不知道为什么更新数组也不会更新视图。

1 个答案:

答案 0 :(得分:2)

事实上似乎是预期的(https://github.com/aurelia/framework/issues/431) 解决此问题的一种快速方法是创建数组的浅表副本

pdb bazel-bin/tensorflow/python/kernel_tests/sparse_split_op_test