简体   繁体   English

聚合物阵列推送出错

[英]Polymer array push gives error

I've used this.push in Polymer but now I got error and I can't find what it is due to.我已经在 Polymer 中使用了this.push但现在出现错误并且我找不到它的原因。 Here's my code:这是我的代码:

 if (!ui.validation.validateForm(this.$.partnerForm)) return; var partner = { name: this.$.partnerName.value, description: this.$.partnerDescription.value }; if (!this.eventData.partners) this.eventData.partners = []; this.push('eventData.partners', partner);

The error is:错误是:

 Uncaught TypeError: Cannot read property 'length' of undefined at HTMLTemplateElement._applySplicesArrayOrder (polymer.html:4991) at HTMLTemplateElement._render (polymer.html:4842) at Debouncer.complete (polymer-mini.html:2081) at Debouncer.boundComplete (polymer-mini.html:2058) at Object._atEndOfMicrotask (polymer-mini.html:2036) at MutationObserver.window.MutationObserver.observe.characterData

When I debug using console.log(this.eventData.partners) data is there, but after that it gives that error.当我使用console.log(this.eventData.partners)调试时,数据在那里,但在那之后它给出了那个错误。 What might be wrong with this push?这种推动可能有什么问题? Thanks.谢谢。

I found the problem.我发现了问题。 I have been used this:我已经用过这个:

if (!this.eventData.partners) this.eventData.partners = [];

I changed it in the following way and it's working now:我按以下方式对其进行了更改,现在可以正常工作了:

if (!this.eventData.partners) this.set('eventData.partners', []);

This is Polymer specific issue.这是聚合物特定的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM