在使用聚合物的电子商务商店应用程序时,我使用聚合物core-ajax加载产品数组,并使用核心动画页面显示产品缩略图和产品详细信息页(完整视图),但我只想在单击每个产品拇指时加载产品详细信息,如何做到这一点?
找到HTML
<div id="article-content" >
<template is="auto-binding" id="page-template" >
<core-ajax
id="ajaxpolo" auto
url="./json/products.json"
handleAs="json"
on-core-response="{{handleResponse}}" response="{{headerList}}" on-core-response="{{postsLoaded}}">
</core-ajax>
<core-animated-pages id="fpages" flex selected="{{$.polo_cards.selected}}" on-core-animated-pages-transition-end="{{transitionend}}" transitions="cross-fade-all slide-from-right">
<section vertical layout>
<div id="noscroll" fit hero-p>
<div id="container" flex horizontal wrap around-justified layout cross-fade >
<section on-tap="{{selectView}}" id="polo_cards" >
<template repeat="{{item in headerList}}">
<div class="card" vertical center center-justified layout hero-id="item-{{item.id}}" hero?="{{$.polo_cards.selected === item.id || lastSelected === item.id }}" > <span cross-fade hero-transition style="">{{item.name}}</span></div>
</template>
</section>
</div>
</div>
</section>
<template repeat="{{item in headerList}}">
<section vertical layout>
<div class="view" flex vertical center center-justified layout hero-id="item-{{item.id}}" hero?="{{$.polo_cards.selected === item.id || $.polo_cards.selected === 0}}" >
<core-icon-button class="go_back" icon="{{$.polo_cards.selected != 0 ? 'arrow-back' : 'menu'}}" on-tap="{{goback}}"></core-icon-button>
{{item.name}} <span cross-fade class="view-cont" style="height:1000px; overflow:scroll;"></span></div>
</section>
</template>
</core-animated-pages>
</template>
发布于 2015-05-28 12:22:20
首先,将核心ajax的auto属性设置为false。auto="false",这将阻止核心-ajax从它自己抓取数据。然后在您想要成为单击/点击处理程序的元素上设置一个on -抽头或on-click属性。然后on-tap="{{getThem}}"创建函数。
getThem: function () {
this.$.ajaxpolo.go();
}那应该就够了。希望能帮上忙。
编辑:你会想要抓取更多的东西与你的事件。在单击/点击处理程序上,将希望获取的项的id添加到泛型属性。(远离正常属性。( dataId )我会叫它。
<div on-tap="{{getThem}}" dataId="{{product_id}}"></div>然后,在您的功能,您得到了更多的事情,从事件,正如我前面说过的。
getThem: function (event, detail, sender) {
var id = sender.attributes.dataId.value;
// do something with id
}我刚刚意识到,当你谈论php的时候,我可能误解了。抱歉的。
https://stackoverflow.com/questions/30498186
复制相似问题