聚合物不重新评估数组绑定表达式
Polymer not reevaluating array-bound expression
我有以下摘录,如果数组中没有元素,应该显示该摘录:
<template is="dom-if" if="[[isEmpty(arrayList)]]">
<p>some text</p>
</template>
该元素具有以下方法:
<script>
(function() {
'use strict';
Polymer({
...
properties: {
arrayList: {
type: Array,
value: function() {return []}
}
},
...
_addElement: function(obj) {
this.push('arrayList', obj);
},
isEmpty: function(obj) {
return obj.length === 0;
}
});
})();
</script>
当我调用 _addElement_
时,[[isEmpty(arrayList)]]
表达式似乎未被计算,因此文本未显示。
我是不是做错了什么?
您需要将表达式更改为 [[isEmpty(arrayList.*)]]
或 [[isEmpty(arrayList.splices)]]
。
否则,isEmpty
函数只会在您将新数组分配给 arrayList
时被调用,而不会在您更改其内容时被调用。您可以在 docs.
中找到更多信息
我有以下摘录,如果数组中没有元素,应该显示该摘录:
<template is="dom-if" if="[[isEmpty(arrayList)]]">
<p>some text</p>
</template>
该元素具有以下方法:
<script>
(function() {
'use strict';
Polymer({
...
properties: {
arrayList: {
type: Array,
value: function() {return []}
}
},
...
_addElement: function(obj) {
this.push('arrayList', obj);
},
isEmpty: function(obj) {
return obj.length === 0;
}
});
})();
</script>
当我调用 _addElement_
时,[[isEmpty(arrayList)]]
表达式似乎未被计算,因此文本未显示。
我是不是做错了什么?
您需要将表达式更改为 [[isEmpty(arrayList.*)]]
或 [[isEmpty(arrayList.splices)]]
。
否则,isEmpty
函数只会在您将新数组分配给 arrayList
时被调用,而不会在您更改其内容时被调用。您可以在 docs.