1

使用此代码,我可以使用变量 { { selected } }attr-for-selected="name"但我想从所选项目打印更多详细信息,而不仅仅是一个属性,在这种情况下是名称。

          <!-- Main Contetnt -->
          <div class="content">
          <h1>{{selected}}</h1>   *This one works fine*

          <h1>{{item.city}}</h1>   *But these two don't*
          <h1>{{item.date}}</h1>
          </div>

我想打印城市日期以及

{{选定}}

有人对这个问题有线索吗?PS:我的元素在代码的底部调用自己,它现在正在工作。但是我会因此而有任何未来的问题吗?

  <dom-module id="x-app">
      <template id="app">

    <iron-ajax url="data/contacts.json" last-response="{{data}}" auto></iron-ajax>

    <paper-drawer-panel id="navDrawerPanel" responsive-width="1280px">

      <div class="nav" drawer>
        <!-- Nav Content -->
      </div>

      <paper-drawer-panel id="mainDrawerPanel" class="main-drawer-panel" main responsive-width="600px"
          drawer-width="[[_computeListWidth(_isMobile)]]" drawer-toggle-attribute="list-toggle"
          narrow="{{_isMobile}}">

        <paper-header-panel class="list-panel" drawer>

          <!-- List Toolbar -->
          <paper-toolbar>
            <paper-icon-button icon="menu" paper-drawer-toggle></paper-icon-button>
          </paper-toolbar>

          <iron-selector selected="{{selected}}" attr-for-selected="name" id="selector">

            <template is="dom-repeat" class="list" items="{{data}}" as="item" id="tmpl">

          <div name="{{item.name}}" on-click="_listTap">
            <div class="item">
              <img class="avatar" src="{{item.image}}">
              <div class="pad">
                <div class="primary">
                  <span>{{index}}</span>
                  <span>{{item.name}}</span>
                </div>
                <div class="secondary">{{item.date}}</div>
                <div class="secondary dim">{{item.city}}</div>
              </div>
              <!-- <iron-icon icon$="{{iconForItem(item)}}"></iron-icon> -->
            </div>
            <div class="border"></div>
          </div>

        </template>

        </iron-selector>


        </paper-header-panel>

        <paper-header-panel class="content-panel" main>

          <!-- Main Toolbar -->
          <paper-toolbar>
            <paper-icon-button icon="arrow-back" list-toggle></paper-icon-button>
          </paper-toolbar>

            <!-- Main Contetnt -->
          <div class="content">
          <h1>{{selected}}</h1> 
          <h1>{{item.city}}</h1>
          <h1>{{item.date}}</h1>
          </div>


        </paper-header-panel>

      </paper-drawer-panel>

    </paper-drawer-panel>

  </template>

  <script>

    Polymer({

      is: 'x-app',
          properties: {

          },
        ready: function() {
         var drawerPanel = document.querySelector('#mainDrawerPanel');
         drawerPanel.openDrawer();

          },

      _computeListWidth: function(isMobile) {
        // when in mobile screen size, make the list be 100% width to cover the whole screen
        return isMobile ? '100%' : '33%';
      },

      _listTap: function() {
        var drawerPanel = document.querySelector('#mainDrawerPanel');
         drawerPanel.closeDrawer();
     }

    });

  </script> 


</dom-module>

<body>
    <x-app></x-app>
</body>
4

1 回答 1

1

使用selected-item而不是selected.

selectedItem返回当前选定的项目(请参阅IronSelectableBehavior

所以你iron-selector应该看起来像:

<iron-selector selected-item="{{selectedItem}}" attr-for-selected="name" id="selector">

然后像这样添加两个条件属性div

<div name="{{item.name}}" city$="[[item.city]]" date$="[[item.date]]" on-click="_listTap">

然后设置一个观察者来监视对以下内容的更改selectedItem

...

observers: [ '_selectedItemChanged(selectedItem)' ],

_selectedItemChanged: function(el) {
  this.city = el.getAttribute('city');
  this.date = el.getAttribute('date');
},

...

然后您可以使用以下内容:

<div class="content">
  <h1>{{city}}</h1>
  <h1>{{date}}</h1>
</div>
于 2015-08-31T04:25:15.893 回答