通过dom

编程入门 行业动态 更新时间:2024-10-24 01:53:42
本文介绍了通过dom-repeat函数设置属性更改不会反映在UI中-Polymer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有对象数组和一个属性,我的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

本文发布于:2023-08-02 11:27:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1277429.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:dom

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!