Authored by uedxwg

修改hotrank数据加载方式 by 赵彪 备:方法可能会重构

@@ -14,6 +14,43 @@ var page = 1, @@ -14,6 +14,43 @@ var page = 1,
14 id = '', 14 id = '',
15 noResult = '<p class="no-result">未找到相关搜索结果</p>'; 15 noResult = '<p class="no-result">未找到相关搜索结果</p>';
16 16
  17 +// var renderRank = {
  18 +// errMsg: '<p class="no-result">未找到相关搜索结果</p>',
  19 +// navSelector: '.goods-nav',
  20 +// rankSelector: '#hotRank',
  21 +// navHTML: null,
  22 +// data: null,
  23 +// inited: 0,
  24 +// setData: function(data) {
  25 +// this.data = data;
  26 +// },
  27 +// showDataEmptyMsg: function() {
  28 +// $(this.rankSelector).append(this.errMsg);
  29 +// },
  30 +// isDataEmpty: function() {
  31 +// if (this.data.indexOf('>') === -1) {
  32 +// return true;
  33 +// } else {
  34 +// return false;
  35 +// }
  36 +// },
  37 +// appendData: function() {
  38 +// if (!this.inited) {
  39 +// this.inited = 1;
  40 +// }
  41 +// $(this.rankSelector).append(this.data);
  42 +// },
  43 +// render: function(data) {
  44 +// this.setData(data);
  45 +// if (!this.isDataEmpty()) {
  46 +// this.appendData();
  47 +// } else {
  48 +// this.showDataEmptyMsg();
  49 +// }
  50 +// }
  51 +
  52 +// };
  53 +
17 function hotrank(page, sort, tabId, notab) { 54 function hotrank(page, sort, tabId, notab) {
18 loading.showLoadingMask(); 55 loading.showLoadingMask();
19 $.ajax({ 56 $.ajax({
@@ -26,15 +63,47 @@ function hotrank(page, sort, tabId, notab) { @@ -26,15 +63,47 @@ function hotrank(page, sort, tabId, notab) {
26 notab: notab 63 notab: notab
27 }, 64 },
28 success: function(data) { 65 success: function(data) {
29 - console.log(data);  
30 - if (page === 1) {  
31 - $('.rank-main').remove();  
32 - }  
33 - if (data === ' ' && $('.rank-main ul li').length < 1) {  
34 - $('#hotRank').html(noResult); 66 +
  67 + // if (page === 1) {
  68 + // $('.no-result').remove();
  69 + // $('.rank-main').remove();
  70 + // }
  71 +
  72 + // if (notab === 1) {
  73 + // if (data === ' ' && $('.rank-main').length < 1) {
  74 + // var hotrankNav = $('.goods-nav').prop("outerHTML");
  75 +
  76 + // $('#hotRank').html(hotrankNav + noResult);
  77 + // } else {
  78 + // $('#hotRank').append(data);
  79 + // }
  80 + // } else {
  81 + // if (data === ' ') {
  82 + // $('#hotRank').html(noResult);
  83 + // } else {
  84 + // $('#hotRank').append(data);
  85 + // }
  86 + // }
  87 + if (data === ' ') {
  88 + if ($('.rank-main').length < 1 && $('.goods-nav').length < 1) {
  89 + $('#hotRank').html(noResult);
  90 + } else {
  91 + if (page === 1) {
  92 + var hotrankNav = $('.goods-nav').prop("outerHTML");
  93 +
  94 + $('#hotRank').html(hotrankNav + noResult);
  95 + }
  96 + }
35 } else { 97 } else {
  98 + $('.no-result').remove();
  99 + $('.rank-main').remove();
36 $('#hotRank').append(data); 100 $('#hotRank').append(data);
37 } 101 }
  102 +
  103 + // renderRank.render(data);
  104 +
  105 +
  106 +
38 lazyLoad($('img.lazy')); 107 lazyLoad($('img.lazy'));
39 $('.rank-main ul li:gt(2)').find('.item-content i').removeClass('top'); 108 $('.rank-main ul li:gt(2)').find('.item-content i').removeClass('top');
40 winH = $(window).height(); 109 winH = $(window).height();
@@ -83,7 +152,11 @@ hotnav.on('tap', function(e) { @@ -83,7 +152,11 @@ hotnav.on('tap', function(e) {
83 id = target.getAttribute('data-id') ? target.getAttribute('data-id') : ''; 152 id = target.getAttribute('data-id') ? target.getAttribute('data-id') : '';
84 sort = target.getAttribute('data-sort') ? target.getAttribute('data-sort') : ''; 153 sort = target.getAttribute('data-sort') ? target.getAttribute('data-sort') : '';
85 page = 1; 154 page = 1;
  155 +
  156 + // notab = renderRank.inited;
86 notab = 1; 157 notab = 1;
  158 +
  159 +
87 hotrank(page, sort, id, notab); 160 hotrank(page, sort, id, notab);
88 } 161 }
89 }); 162 });