0

我正在尝试构建一个非常简单的工具来在我的工作中使用。我在 eBay 工作,目前可用的工具对于这项任务来说很麻烦。我们被要求比较文本和图像,以检查卖家是否没有窃取彼此的内容。我正在使用 eBay Trading API 和创建开发者帐户时提供的示例 HTML/CSS/Javascript 代码。最终我希望实现的是一个简单的页面,将两个项目的照片和描述并排显示。但是,现在我只是试图编辑给出的示例代码以显示拍卖的开始日期。

我的问题是:我正在尝试添加一个变量,该变量的值由 API 的响应确定。其中一些是在示例中提供的,但是,当我将自己var starttime = items.listingInfo.startTime的变量添加到函数中并将变量添加到 HTML 表中时,不会显示任何数据,包括添加之前显示的数据。不幸的是,我对 javascript 的了解并不多,所以我不确定我是否正确地表达了这个问题,更不用说让我添加的语法正确了。我究竟做错了什么?

下面是示例文本,我starttime在 HTML 表中添加了一个声明变量 ( ) 和一个

<html>
<head>
<title>eBay Search Results</title>
<style type="text/css">body { font-family: arial,sans-serif;} </style>
</head> 
<body>
<h1>eBay Search Results</h1>
<div id="results"></div>

<script>
function _cb_findItemsByKeywords(root)
{
  var items = root.findItemsByKeywordsResponse[0].searchResult[0].item || [];
  var html = [];
  html.push('<table width="100%" border="0" cellspacing="0" cellpadding="3"><tbody>');

  for (var i = 0; i < items.length; ++i)  
  {
    var item     = items[i];
    var title    = item.title;
        var viewitem = item.viewItemURL;
    var starttime = items.listingInfo.startTime;

    if (null != title && null != viewitem)
    {
      html.push('<tr><td>' + '<img src="' + pic + '" border="0">' + '</td>' + 
        '<td><a href="' + viewitem + '" target="_blank">' + title + '</a>' + starttime + '</td></tr>');
    }
  }
  html.push('</tbody></table>');
  document.getElementById("results").innerHTML = html.join("");
}
</script>

<!--
Use the value of your appid for the appid parameter below.
-->
<script src=http://svcs.ebay.com/services/search/FindingService/v1?SECURITY-APPNAME=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&OPERATION-NAME=findItemsByKeywords&SERVICE-VERSION=1.0.0&RESPONSE-DATA-FORMAT=JSON&callback=_cb_findItemsByKeywords&REST-PAYLOAD&keywords=iphone%203g&paginationInput.entriesPerPage=3>
</script>
</body>
</html>"
4

1 回答 1

1

如果您认为listingInfo是单个项目的属性,并且它是具有属性的对象startTime,那么正确的语法是:

var item     = items[i];
var title    = item.title;
var viewitem = item.viewItemURL;
var starttime = item.listingInfo.startTime;

您当前引用items的是项目数组,而不是单个项目。

更新

我通过您在评论中输入的URL进行了调查。这个特定问题的解决方案是:

var starttime = item.listingInfo[0].startTime;

我希望这会有所帮助。请查看常见问题解答;恕我直言,这个问题超出了本网站的范围(这个问题真的很窄,不太可能帮助其他任何人)。我推荐Mozilla 开发者网络作为了解更多关于 JavaScript 的资源。

于 2012-02-29T21:49:35.900 回答