【问题标题】:Polymer Load Product Page data from JSONPolymer 从 JSON 加载产品页面数据
【发布时间】:2015-05-28 05:49:46
【问题描述】:

使用聚合物处理电子商务商店应用程序 我正在使用聚合物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>

【问题讨论】:

    标签: javascript jquery polymer


    【解决方案1】:

    首先您将核心 ajax 的 auto 属性设置为 false。 auto="false" 这将阻止 core-ajax 自己获取数据。然后在您想成为点击/点击处理程序的元素上设置点击或点击属性。 on-tap="{{getThem}}" 然后创建函数。

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

    应该得到它。希望能帮助到你。

    编辑:您将希望在您的活动中获得更多的东西。 在单击/点击处理程序上,将您希望获取的项目的 id 添加到通用属性。 (远离正常属性。即 id、title 等)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 时我可能误解了。对不起。

    【讨论】:

    • 我已经做过类似的事情template.selectView = function(e,detail,sender){ this.async(function() { product_ajax.go(); }); 你能告诉我如何发送一些参数并在该页面中读取它,而不使用 PHP 吗?我想根据 id 加载产品数据
    • 您可以使用 core-ajax 参数属性发送帖子数据。您可以像平常一样构建一个对象 this.postdata = {id: 100};将其设置为 params 属性 params="{{postdata}}"。我将用示例更新答案
    • 是的,但是我如何在 ajax 页面中读取这个参数?没有 php
    • 我想我误解了你问题的第二部分。我已经更新了答案。如果这没有帮助,请告诉我,我会尽力为您提供进一步的帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-01-22
    • 2020-09-28
    • 1970-01-01
    • 2021-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多