字符串插值在Aurelia中的Viewmodel中更改为对象后未获得更新

时间:2017-02-07 17:56:10

标签: javascript aurelia aurelia-binding

我在Aurelia的View中有一个元素,当Viewmodel中的对象更新时,它没有得到更新。我已经看过有关Pub / Sub和Event Aggregators的文档,但是对于我想做的事情来说这看起来有点笨拙,因为我不想在两个不同的资源之间进行通信,而只是在一个View及其Viewmodel中

当Viewmodel中的对象发生更改时,我不知道如何在视图中正确更新(或触发更新)字符串插值。

我的代码如下

myview.html

<h1>My List</h1>
<ul>
    <li repeat.for="group of modelObject.groups">
        <span>${group.id}</span>
        <span repeat.for="state of group.region">${state}</span>
    </li>
<ul>
<button click.delegate(editModelObject())>Edit</button>

myviewmodel.js

constructor()
{
    this.modelObject = {
        <other stuff>,
        "groups": [
            {
               "id": "default",
               "regions" : ["NY", "CT", "NJ"]
            },
            {
               "id": "west",
               "regions" : ["CA", "OR"]
            }
        ],
        <more stuff>
    }
}

editModelObject() {
    <something that updates both the id and regions of a group in this.modelObject>
}

出于某种原因,状态在视图中正确地改变,但id不是。我是否需要使用Pub / Sub之类的东西来使双向绑定正常工作?或者有一件简单的事情我错过了或做错了吗?

1 个答案:

答案 0 :(得分:1)

如果更改其中一个数组对象的属性,则此方法有效。但是如果你指定一个数组的索引,这不起作用,因为这需要进行脏检查。见https://github.com/aurelia/binding/issues/64

要解决您的问题,您应该使用invalid conversion from 'const int*' to 'const int32_t* {aka const long int*}' [-fpermissive] test4 line 244, external location: /home/wizard/Desktop/eigen/Eigen/src/Core/arch/NEON/PacketMath.h C/C++ Problem invalid conversion from 'const int*' to 'const int32_t* {aka const long int*}' [-fpermissive] test4 line 247, external location: /home/wizard/Desktop/eigen/Eigen/src/Core/arch/NEON/PacketMath.h C/C++ Problem invalid conversion from 'const int*' to 'const int32_t* {aka const long int*}' [-fpermissive] test4 line 259, external location: /home/wizard/Desktop/eigen/Eigen/src/Core/arch/NEON/PacketMath.h C/C++ Problem invalid conversion from 'const int*' to 'const int32_t* {aka const long int*}' [-fpermissive] test4 line 260, external location: /home/wizard/Desktop/eigen/Eigen/src/Core/arch/NEON/PacketMath.h C/C++ Problem invalid conversion from 'int*' to 'int32_t* {aka long int*}' [-fpermissive] test4 line 265, external location: /home/wizard/Desktop/eigen/Eigen/src/Core/arch/NEON/PacketMath.h C/C++ Problem invalid conversion from 'int*' to 'int32_t* {aka long int*}' [-fpermissive] test4 line 268, external location: /home/wizard/Desktop/eigen/Eigen/src/Core/arch/NEON/PacketMath.h C/C++ Problem invalid conversion from 'int*' to 'int32_t* {aka long int*}' [-fpermissive] test4 line 309, external location: /home/wizard/Desktop/eigen/Eigen/src/Core/arch/NEON/PacketMath.h C/C++ Problem 而不是索引编号。例如:

splice()

正在运行示例https://gist.run/?id=087bc928de6532784eaf834eb918cffa