如何向动态创建的组件添加属性

时间:2014-01-04 23:56:19

标签: dart dart-polymer

我想将已发布的属性添加到动态创建的组件中。该组件的代码如下所示:

  <!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'
     $[ 'names' ].children
                 .add( new Element.tag( 'name-form' ) );

我想添加一个属性receiver ='patient'。

由于

1 个答案:

答案 0 :(得分:0)

这是Custom Events in Nested Polymer Dart UI的后续问题吗?在这种情况下,没有必要创建已发布的属性。您只需在课程中添加role之类的字段,并将此字段设置为'nok-form''patient-form'

Element nameForm = new Element.tag( 'name-form' )
nameForm.role = 'nok-form';
 $[ 'names' ].children
                 .add(nameForm);

如果要在标记(HTML)中设置值,则只需要已发布的属性。