dom 中的聚合物可观察对象-重复未获取更新
Polymer observable object in dom-repeat not getting update
我正在尝试以 dom 重复显示包含数组的对象。
数据结构如下:
answerObject: {firstQuestion: ["one", "two"],
第二个问题:["three", "four"]}
我在嵌套的 dom-repeat 中使用计算绑定将对象转换为数组,然后使用另一个 dom-repeat 显示数组的内容。
<ul>
<template is="dom-repeat" items="[[_makeArray(answerObject)]]" as="question">
<li>[[question.key]]</li>
<ul>
<template is="dom-repeat" items="[[question.listOfAnswer]]" as="answer">
<li>[[answer]]</li>
</template>
</ul>
</template>
我创建了 answerObject 属性 如下:
answerObject: {
type: Object,
notify: true,
value: {firstQuestion: ["one", "two", "three"],
secondQuestion: ["four","five"] },
observer: '_answerChanged'
},
我尝试了所有不同的方法来观察对象或数组,none 触发了函数“_answerChanged”或“_makeArray”。
/* mutating object and then notifyPath */
this.set('answerObject.firstQuestion', ["newone"]);
this.notifyPath('answerObject.firstQuestion');
/* mutating array then notifySplices */
this.push('answerObject.secondQuestion',"six");
this.notifySplices('answerObject.secondQuestion', [
{index:3, removed: [], addedCount: 1, object: _this.answerObject.secondQuestion, type:'splice'}
]);
/* dirty check */
var array = this.answerObject.firstQuestion;
this.answerObject.firstQuestion=[];
this.answerObject.firstQuestion = array;
任何建议我错过了什么?谢谢。
没有触发观察者,因为不支持你的场景
Primitive array items are not supported. This is because primitives (like number, string and boolean values) with the same
value are represented by the same object.
目前推荐的解决方法(也在我之前的 link 中说明)是,您只需用一个简单的对象包装您的原始值。
所以,而不是这个:
["one", "two", "three"]
你使用这样的东西:
[{ value: "one" }, { value: "two" }, { value: "three" }]
我正在尝试以 dom 重复显示包含数组的对象。 数据结构如下: answerObject: {firstQuestion: ["one", "two"], 第二个问题:["three", "four"]}
我在嵌套的 dom-repeat 中使用计算绑定将对象转换为数组,然后使用另一个 dom-repeat 显示数组的内容。
<ul>
<template is="dom-repeat" items="[[_makeArray(answerObject)]]" as="question">
<li>[[question.key]]</li>
<ul>
<template is="dom-repeat" items="[[question.listOfAnswer]]" as="answer">
<li>[[answer]]</li>
</template>
</ul>
</template>
我创建了 answerObject 属性 如下:
answerObject: {
type: Object,
notify: true,
value: {firstQuestion: ["one", "two", "three"],
secondQuestion: ["four","five"] },
observer: '_answerChanged'
},
我尝试了所有不同的方法来观察对象或数组,none 触发了函数“_answerChanged”或“_makeArray”。
/* mutating object and then notifyPath */
this.set('answerObject.firstQuestion', ["newone"]);
this.notifyPath('answerObject.firstQuestion');
/* mutating array then notifySplices */
this.push('answerObject.secondQuestion',"six");
this.notifySplices('answerObject.secondQuestion', [
{index:3, removed: [], addedCount: 1, object: _this.answerObject.secondQuestion, type:'splice'}
]);
/* dirty check */
var array = this.answerObject.firstQuestion;
this.answerObject.firstQuestion=[];
this.answerObject.firstQuestion = array;
任何建议我错过了什么?谢谢。
没有触发观察者,因为不支持你的场景
Primitive array items are not supported. This is because primitives (like number, string and boolean values) with the same value are represented by the same object.
目前推荐的解决方法(也在我之前的 link 中说明)是,您只需用一个简单的对象包装您的原始值。
所以,而不是这个:
["one", "two", "three"]
你使用这样的东西:
[{ value: "one" }, { value: "two" }, { value: "three" }]