Jquery .append语法

时间:2013-12-28 12:52:45

标签: jquery append

我有coldfusion网站将有超过10000个产品,如果我使用普通的cfquery加载具有超过1000条记录的特定sub_cat_id的产品,该页面将永远加载并减慢速度,所以我使用JSON格式返回结果,我遇到的问题是将返回的结果附加到页面上的特定div,我知道某处存在语法错误但我想知道在使用追加函数时如何以及何时使用''或+ ,我是javascript的新手,所以请光临我,这是我的代码,下面是追加功能:

// Read the products
$.ajax({
url: "js/gtprod.cfm?filter=brand&brand_id=115",
dataType: "json",
success: function(data) {
  var row, sData, _len, _i;
  // Run the data thru queryToObject
  data = queryToObject(data);
  // Convert the object to a string to display it
  sData = JSON.stringify(data);

  // Print all products
  $('#product').append('<h3>PRODUCTS:</h3>');
  // Loop over the query
  for (_i = 0, _len = data.length; _i < _len; _i++) {
    row = data[_i];
    $('#main').append('<div id="product" class="mix' + row.make_title + row.model_title +'" data-name="'+ row.product_title +'"><div id="productleft"></div><div id="productright"> '<h3 align="left">' + '<a href="products-detail.cfm?product_id=' + row.product_id + '">' + row.product_title + '</a>' + '</h3>'<div align="left" id="productrightmidsection" >VEHICLE: + '<span>' + row.make_title + '-' + row.model_title + '</span>' + '|' + 'Manufacturer:' + '<span>' + row.brand_name + '</span>' <div id="productview">'<a href="products-detail.cfm?product_id=' + row.product_id + '" class="productview">' + View &raquo; + '</a>'</div></div></div></div>' );
  }
}
});

非常感谢任何帮助

1 个答案:

答案 0 :(得分:1)

使用此功能,您有连接问题

    $('#main').append('<div id="product" class="mix' + row.make_title + row.model_title +'" data-name="'+ row.product_title +'"><div id="productleft"></div><div id="productright"> <h3 align="left"><a href="products-detail.cfm?product_id=' + row.product_id + '">' + row.product_title + '</a></h3><div align="left" id="productrightmidsection" >VEHICLE: <span>' + row.make_title + '-' + row.model_title + '</span> | Manufacturer: <span>' + row.brand_name + '</span> <div id="productview"><a href="products-detail.cfm?product_id=' + row.product_id + '" class="productview"> View &raquo; </a></div></div></div></div>' );