gpt4 book ai didi

polymer - 当从 dom-repeat 的函数设置属性更改时,它不会反射(reflect)在 UI 中 - Polymer

转载 作者:行者123 更新时间:2023-12-02 03:08:25 24 4
gpt4 key购买 nike

我有一个对象数组和一个属性,我的 dom-repeat 结构如下所示

     <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>

我有属性(property)

 properties:{
myProperty:{
type:Boolean
}
}

每次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-repeat 之后,我调用了一些函数,当我更改值时,它会在所有地方得到反射(reflect)

    this.myProperty = true;

但是为什么在 dom-repeat 调用的函数中更改值时它不起作用?我尝试了所有 3 种更新对象的方法

笨蛋:https://plnkr.co/edit/iAStve97dTTD9cv6iygX?p=preview

最佳答案

通过 this.myValue = 'somevalue' 设置一个变量;不会更新绑定(bind)。

最好通过this.set('variablename', 'variablevalue');设置变量

您也可以在通过 this.variablename = 'variablevalue'; 设置属性后this.notifyPath('变量名');

关于polymer - 当从 dom-repeat 的函数设置属性更改时,它不会反射(reflect)在 UI 中 - Polymer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41184556/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com