admin管理员组文章数量:1252924
I'm developing for sending an Array as element's attribute.
File form-list.html
<dom-module id="form-list">
<template>
<div>{{title}} - {{owner}} </div>
<form>
<template is="dom-repeat" items="{{inputAndLabel}}">
<div><label>{{item.tag}} {{owner}}</label><input type="{{item.type}}" value="{{item.defaultValue}}"></div>
</template>
</form>
</template>
<script>
Polymer({
is: 'form-list',
properties: {
owner: {
value:"Mechanical",
},
inputAndLabel: {
type: Array,
value: function() { return []; }
}
},
ready: function() {
this.title = 'Formulario: Usuario';
}
});
</script>
</dom-module>
I'm developing for sending an Array as element's attribute.
File form-list.html
<dom-module id="form-list">
<template>
<div>{{title}} - {{owner}} </div>
<form>
<template is="dom-repeat" items="{{inputAndLabel}}">
<div><label>{{item.tag}} {{owner}}</label><input type="{{item.type}}" value="{{item.defaultValue}}"></div>
</template>
</form>
</template>
<script>
Polymer({
is: 'form-list',
properties: {
owner: {
value:"Mechanical",
},
inputAndLabel: {
type: Array,
value: function() { return []; }
}
},
ready: function() {
this.title = 'Formulario: Usuario';
}
});
</script>
</dom-module>
So, for using the element and pass the inputAndLabel propertie (it's an Array) that is not work, but the owner property works (it's a string).
<form-list inputAndLabel="[
{defaultValue: '', type:'text', tag: 'Nombre' },
{defaultValue: '', type:'text', tag: 'Apellido' },
{defaultValue: '', type:'text', tag: 'Email' },
{defaultValue: '', type:'text', tag: 'Dirección' }]" owner="Eternal">
</form-list>
How to send an array as custom element's property?
Thanks
Share Improve this question edited Jul 29, 2018 at 22:26 Intervalia 11k2 gold badges33 silver badges70 bronze badges asked Feb 18, 2017 at 22:46 Eday GonzalezEday Gonzalez 3101 gold badge2 silver badges13 bronze badges 01 Answer
Reset to default 9According to polymer documentation you can pass an array as an element attribute it you respect the strict JSON notation.
For object and array properties you can pass an object or array in JSON format:
<my-element book='{ "title": "Persuasion", "author": "Austen" }'></my-element>
Note that JSON requires double quotes, as shown above.
<form-list input-and-label='[
{"defaultValue": "", "type":"text", "tag": "Nombre" },
{"defaultValue": "", "type":"text", "tag": "Apellido" },
{"defaultValue": "", "type":"text", "tag": "Email" },
{"defaultValue": "", "type":"text", "tag": "Dirección" }]' owner="Eternal">
</form-list>
Also note that the corresponding attribute for the inputAndLabel
property is written input-and-label
.
本文标签: javascriptHow to pass an Array as element39s AttributeStack Overflow
版权声明:本文标题:javascript - How to pass an Array as element's Attribute? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740319027a2260873.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论