使用此代码,我可以使用变量 { { 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>