[英]Polymer: how to do 'this.set' or 'notifyPath' on dinamically generated subproperties of JSON object?
var newUser = evt.detail.response[0]; var keys = Object.keys(evt.detail.response[0]); var cpt = []; keys.forEach(key => { if (this.storedUser[key] != newUser[key]) { this.storedUser[key] = newUser[key]; cpt.push(key); } });
如何通知此类变量的更改?
由于我不能做:
this.set('storedUser[key]', newUser[key]);
也不:
this.set('storedUser'[key], newUser[key]);
也不:
this.notifyPath('storedUser[key]');
也不:
this.notifyPath('storedUser'[key]);
您可以做(这是一个字符串,因此请先连接它):
const key = "storedUser."+key;
this.set(key, []);
来自docs: https : //www.polymer-project.org/2.0/docs/devguide/model-data (与1.0相同)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.