如何将值从一个自定义元素传递到Polymerjs 1.0中的另一个元素

时间:2016-09-06 11:52:33

标签: polymer-1.0

我有一个自定义元素element1.html,其中我们使用iron-ajax来调用服务,从服务接收的数据用于填充下拉菜单

const string publishDatePartId = "publishDatePart";

var publishDateXmlPart = wordDocument.MainDocumentPart.AddNewPart<CustomXmlPart>("application/xml", publishDatePartId);

var writer = new XmlTextWriter(publishDateXmlPart.GetStream(FileMode.Create), System.Text.Encoding.UTF8);

writer.WriteRaw($"<CoverPageProperties xmlns=\"http://schemas.microsoft.com/office/2006/coverPageProps\">" +
                $"<PublishDate>{DateTime.Today.ToShortDateString()}</PublishDate>" +
                $"</CoverPageProperties>");

writer.Flush();

writer.Close();

var customXmlPropertiesPart = publishDateXmlPart.AddNewPart<CustomXmlPropertiesPart>(publishDatePartId);

customXmlPropertiesPart.DataStoreItem = new DocumentFormat.OpenXml.CustomXmlDataProperties.DataStoreItem()
{
    //I don't know what this ID is, but it seems to somehow relate to the Publish Date
    ItemId = "{55AF091B-3C7A-41E3-B477-F2FDAA23CFDA}"
};

在上面的下拉列表中,每个值都是一个链接,当点击它时它有一个唯一的键将路由到其他部分(其他页面),其中将使用锚标记中的“keyValue”显示数据。在本节中我使用另一个自定义元素(element2.html)。那么如何将element1.html中的keyValue传递给element2.html

<dom-module id="element1">
<iron-ajax auto
    url="../sites.json"    
    handle-as="json"
    on-response="handleResponse"
    ></iron-ajax>
<paper-dropdown-menu-light label="select site" noink no-animations>
    <paper-listbox class="dropdown-content sitedropdown">
      <template is="dom-repeat" items="{{data}}">
        <a class="sitelist" on-tap="testclick" data-cus$="{{item.keyValue}}"  href$="{{baseUrl}}site/{{item.keyValue}}" tabindex="-1">         
          <paper-item raised>{{item.Name}}</paper-item>
        </a>         
      </template>          
    </paper-listbox>
</paper-dropdown-menu-light>

<script>
      Polymer({
        is: 'element1',
     properties: {     
        },
        handleResponse:function(e,request){
       this.data=e.detail.response;
        },
    testclick : function(e){
      console.log(e.target.parentNode.getAttribute('data-cus'));
      this.keyValue=e.target.parentNode.getAttribute('data-cus');
    }     
      });

  </script>
</dom-module>

0 个答案:

没有答案