如何向动态创建的组件添加属性 [英] How to add attributes to a dynamically created component
问题描述
我想将已发布的属性添加到动态创建的组件。组件的代码如下所示:
I would like to add a published attribute to a dynamically created component. The code for the component is shown below:
<!DOCTYPE html>
<link rel="import" href="name-form.html">
<link rel="import" href="../../shared/red-asterisk.html">
<polymer-element name='name-view'>
<template>
<div id='name-view' class='flex-row-container view'>
<section id='row0' class='flex-row' >
<button id='add-name-btn'
class='button add-button'
on-click='{{addName}}'
autofocus>Add Name</button>
<red-asterisk></red-asterisk>
</section >
<section id='names' class='flex-column'>
</section>
</div>
</template>
<script type="application/dart">
import 'package:polymer/polymer.dart';
import 'dart:html' show Event, Node, Element;
@CustomTag( 'name-view' )
class NameViewForm extends PolymerEment
{
@published String receiver = '';
NameViewForm.created() : super.created();
void addName( Event e, var detail, Node target )
{
if( $[ 'names' ].children.length < 1 )
{
$[ 'names' ].children
.add( new Element.tag( 'name-form' ) );
}
$['names'].on["deleteDispatch"]
.listen( (Event e)
{
(e.target as Element).remove();
});
}
}
</script>
</polymer-element>
它是元素('name-form'由
It is the element ('name-form' created by
$[ 'names' ].children
.add( new Element.tag( 'name-form' ) );
我要添加一个属性receiver ='patient'。
to which I would like to add an attribute receiver='patient'.
感谢
推荐答案
这是一个后续问题在嵌套聚合物Dart UI
?在这种情况下,不需要创建一个已发布的属性你可以只添加一个字段 role
并将此字段设置为'nok-form'
或'patient-form'
。
Is this a follow up question to Custom Events in Nested Polymer Dart UI
?. In this case it would not be necessary to create a published attribute. You can just add a field like role
in the class and set this field to 'nok-form'
or 'patient-form'
.
Element nameForm = new Element.tag( 'name-form' )
nameForm.role = 'nok-form';
$[ 'names' ].children
.add(nameForm);
当您想在标记(HTML)中设置值时,只需要一个已发布的属性。
You only need a published attribute when you want to set the value in markup (HTML).
这篇关于如何向动态创建的组件添加属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!