Blog

Tutorial: Amazon.com Search API

Posted on

Object Assembly

Appending Item Objects Code

And finally, the elements are appended to their parents until everything is contained under the searchResults <div> element. Note the conditional statement for instances where there are zero results.

// Build Item Content
      a_ig.appendChild(ig);
      td1.appendChild(a_ig); // Thumbnail
      td2.appendChild(li1); // Title
      td2.appendChild(li4); // Description
      subtd1.appendChild(li2); // Vendor
      subtd2.appendChild(li3); // Price
      subtr.appendChild(subtd1);
      subtr.appendChild(subtd2);
      subtbody.appendChild(subtr);
      subtable.appendChild(subtbody);
      td3.appendChild(subtable);
      tr1.appendChild(td1);
      tr1.appendChild(td2);
      tr2.appendChild(td3);
      tbody.appendChild(tr1);
      tbody.appendChild(tr2);
      maintable.appendChild(tbody);
      content.appendChild(maintable);
      container.appendChild(content);
      container.appendChild(subInfo); // Ratings, Reviews &amp; Sellers
      iDiv.appendChild(container);
      scoller.appendChild(iDiv);

Appending Result Collection Objects Code

if(count != 0)
   {
      // Build Result List
      sa_listTop.appendChild(viewOptions);
      sa_listTop.appendChild(sortBy);
      sa_listTop.appendChild(scoller);

      // Build Pagination
      var pagination = paginate (tmpData.ItemSet.pagenum, tmpData.ItemSet.TotalResults, tmpData.ItemSet.category, tmpData.ItemSet.sort, tmpData.ItemSet.keywords);
      sa_listTop.appendChild(pagination);
      gDiv.appendChild(sa_listTop);
      gDiv.appendChild(cel('p'));
   }
   else // If there are no results
   {
      gDiv.appendChild(ctn(&quot;sorry, no results found for '&quot; + getEl('asch').value + &quot;'&quot;));
      gDiv.appendChild(cel('p'));
   }