Polymer 属性更改从dom重复设置时不反映在UI中';s功能聚合物
我有一个对象数组和一个属性,我的dom重复结构如下Polymer 属性更改从dom重复设置时不反映在UI中';s功能聚合物,polymer,polymer-1.0,polymer-1.x,dom-repeat,Polymer,Polymer 1.0,Polymer 1.x,Dom Repeat,我有一个对象数组和一个属性,我的dom重复结构如下 <template is="dom-repeat" items="{{arrayOfObj}}"> //first dom repeat <span>[[myProperty]]<span> //here also its not updating <template is="dom-if" if="[[_chec
<template is="dom-repeat" items="{{arrayOfObj}}"> //first dom repeat
<span>[[myProperty]]<span> //here also its not updating
<template is="dom-if" if="[[_checkSomeCondition()]]"> //calling method from dom-if
<span>[[myProperty]]<span> //here its not getting updated value
</template>
</template>
每次dom repeat迭代时都会调用我的函数
_checkSomeCondition:function() { //I'll check and set property
if(some condition){
this.myProperty = true;
return true;
}
else{
this.myProperty = false;
return true;
}
console.log(this.myProperty); //I'll get the updated value on console
}
但它不会在屏幕上改变!!它将显示它第一次在_checkSomeCondition内设置的任何数据!!但在控制台中,它的更新
为了进行测试,我插入了一个按钮,在点击该按钮时重复渲染dom之后,我调用了一些函数,在那个里,当我更改值时,它到处都会反映出来
this.myProperty = true;
但是,当dom repeat调用的函数中的值发生变化时,为什么它不起作用呢??我尝试了3种更新对象的方法
普朗克:试试看
<template is="dom-if" if="[[_checkSomeCondition(myProperty)]]"> //calling method from dom-if
<span>[[myProperty]]<span> //here its not getting updated value
</template>
通过this.myValue='somevalue'设置变量;不会更新绑定 最好通过
this.set('variablename','variablevalue')设置变量代码>
您还可以在通过this.variablename='variablevalue'设置属性之后;这个.notifyPath('variablename'
) 我修改了您的代码,如下所示。我不确定这对你的先生是否有帮助。请看一看可能有助于提出想法
{{myProperty}}//这里也没有更新
{{{u checkSomeCondition(index)}}//这里没有更新的值
您的\u checkSomeCondition
方法将是:
\u checkSomeCondition:function(){//我将检查并设置属性
控制台日志(索引);
if(){
this.myProperty='true';
}否则{
this.myProperty='false';
}
//返回要在UI中显示的任何内容
返回此.myProperty;
console.log(this.myProperty);//我将在控制台上获取更新的值
},
您的myProperty应该通知更改。因此属性应该具有notify:true
有了这段代码,我可以像预期的那样看到UI中的更改。让我知道它是否有用我不知道它是否有效!!但如果我想更新很多属性,我不能从函数调用发送所有属性,这种方法是不可行的!!以这个Plunk为例,说明如何在聚合物中使用反应变量。我已经包括了修改数组中变量和使用数组外部变量进行计算的示例。你可能只需要重新思考你想要实现的目标。嘿,谢谢你的回复!!我尝试了你的解决方案,但仍然有相同的问题!请检查更新的plunkerI我觉得一个过滤函数真的没有必要像你这样更新一个值。为什么不通过另一个方法动态设置对象上的值呢?实际上这是演示代码,所以我在if和else语句中都返回true,但在我的原始代码中,我必须做更多的验证!但语法几乎保持不变。。
<template is="dom-if" if="[[_checkSomeCondition(myProperty)]]"> //calling method from dom-if
<span>[[myProperty]]<span> //here its not getting updated value
</template>
_checkSomeCondition: function(property) {