我有对象数组和一个属性,我的dom-repeat结构如下所示
I have array of objects and a property, my dom-repeat structure is like as below
<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>我有一个财产
properties:{ myProperty:{ type:Boolean } }每次重复执行dom-repeat时都会调用我的函数
my function is called each time when dom-repeat iterates
_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内首次设置的任何数据!但是在控制台中更新
but its not changing in screen!! It will display whatever data it set first time inside _checkSomeCondition !! but in console its updating
为了进行测试,我插入了一个按钮,并在点击该按钮后渲染了所有dom-repeat之后,我调用了一些函数,当我更改值时,它会无处不在
For testing I inserted a button and after all dom-repeat rendered on tapping that button I called some function ,there when I changed value it get reflected everywhere
this.myProperty = true;但是当在dom-repeat调用的函数中更改值时为什么它不起作用?我尝试了所有三种更新对象的方法
but why its not working when value is changed inside a function which is called by dom-repeat?? I tried all 3 ways of updating a object
柱塞: plnkr.co/edit/iAStve97dTTD9cv6iygX?p=preview
推荐答案通过this.myValue ='somevalue';设置变量.将不会更新绑定.
Setting a variable via this.myValue = 'somevalue'; won't update binding.
最好通过this.set('variablename', 'variablevalue');
通过this.variablename = 'variablevalue'; this.notifyPath('variablename'设置属性后,您还可以;
You could also, after setting a property via this.variablename = 'variablevalue'; this.notifyPath('variablename');
更多推荐
通过dom
发布评论