Polymer Load Product Page data from JSON

喜欢而已 提交于 2019-12-25 07:18:11

问题


Working with an e-commerce store application with polymer I'm loading products array using polymer core-ajax and using core-animated pages to display product thumbnail and product detail page (full view) but I only wanted to load the product details when clicking on each product thumb, How can I do this

Find the 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>

回答1:


first you would set the auto attribute of core ajax to false. auto="false" that would stop core-ajax from grabbing data by it's self. then set up a on-tap or on-click attribute on the element you want to be the click / tap handler. on-tap="{{getThem}}" then create the function.

getThem: function () {
  this.$.ajaxpolo.go();
}

that should get it. hope it helps.

edit: you will want to grab a few more things with your event. on the click / tap handler add the id of the item you wish to get to a generic attribute. (stay away from normal attributes. ie id, title and so forth) dataId I will call it.

<div on-tap="{{getThem}}" dataId="{{product_id}}"></div>

then in your function you get a few more things with the event as i said before.

getThem: function (event, detail, sender) {
  var id = sender.attributes.dataId.value;
  // do something with id
}

i just realized i may have misunderstood when you were talking about php. sorry.



来源:https://stackoverflow.com/questions/30498186/polymer-load-product-page-data-from-json

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!