简体   繁体   English

Dart + Polymer,如何绑定到以编程方式生成的元素,textarea,select,optgroup

[英]Dart + Polymer, how to bind to programmatically generated elements, textarea, select, optgroup

I'm trying to create a form Polymer component where form elements are generated on the fly. 我正在尝试创建一个Form Polymer组件,其中动态生成表单元素。 I've looked, and so far the only way to bind the value attribute is by using .injectBoundHtml . 我已经看过了,到目前为止,绑定value属性的唯一方法是使用.injectBoundHtml This does not work with all component types, I'm trying to bind the value of a <textarea> , and this is what I get: 这不适用于所有组件类型,我试图绑定<textarea>的值,这就是我得到的:

Removing disallowed attribute <TEXTAREA value="{{ results[ "comments" ] }}">

My work around was to add: textareaID.addEventListener('change', updateValueMap) 我的解决方法是添加: textareaID.addEventListener('change', updateValueMap)

I'm hoping someone could tell me why value is disallowed, and/or if there is a better way to programmatically assign bound attributes in Polymer . 我希望有人能告诉我为什么不允许使用value ,和/或是否有更好的方法以编程方式在Polymer中分配绑定属性 Please :)! 请 :)!

Thanks to Gunter's suggestion, and passing a node validator: 感谢Gunter的建议,并通过了一个节点验证器:

var val = new NodeValidatorBuilder.common()
  ..allowElement('textarea', attributes:['value']);
this.injectBoundHtml(getElementStr(i), element:selP, validator:val);

Textarea doesn't have a value attribute. Textarea没有value属性。 Try this instead 试试这个

<textarea>{{results['comments']}}</textarea>

For more information about the message Removing disallowed attribute see How to create shadow DOM programmatically in Dart? 有关消息“ Removing disallowed attribute更多信息,请参见如何在Dart中以编程方式创建阴影DOM?

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

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