Authored by xuqi

trigger input search

... ... @@ -70,43 +70,46 @@ function searchResult() {
i = 0,
html = '';
// 遍历首字母搜索
$.each(brandsData, function(k, v) {
if ($.isArray(v)) {
if (keyword !== '') {
// 遍历首字母搜索
$.each(brandsData, function(k, v) {
if ($.isArray(v)) {
// 遍历品牌,进行匹配
$.each(v, function(i, brand) {
if (brand.name.toLowerCase().indexOf(keyword) > -1) {
result[k] = result[k] || [];
result[k].push(brand);
}
});
}
});
// 遍历品牌,进行匹配
// 根据搜索结果生成 HTML
$.each(result, function(k, v) {
var brandHtml = ['<div class="brand-list bar-', i, '">'];
i++;
brandHtml.push('<div class="title-bar"><h2>');
brandHtml.push(k);
brandHtml.push('</h2></div>');
$.each(v, function(i, brand) {
if (brand.name.toLowerCase().indexOf(keyword) > -1) {
result[k] = result[k] || [];
result[k].push(brand);
brandHtml.push('<p><a href="' + brand.url + '">' + brand.name);
if (brand.isNew) {
brandHtml.push('<i class="icon-hot">HOT</i>');
}
if (brand.isHot) {
brandHtml.push('<i class="icon-new">NEW</i>');
}
brandHtml.push('</a></p>');
});
}
});
brandHtml.push('</div>');
html += brandHtml.join('');
// 根据搜索结果生成 HTML
$.each(result, function(k, v) {
var brandHtml = ['<div class="brand-list bar-', i, '">'];
i++;
brandHtml.push('<div class="title-bar"><h2>');
brandHtml.push(k);
brandHtml.push('</h2></div>');
$.each(v, function(i, brand) {
brandHtml.push('<p><a href="' + brand.url + '">' + brand.name);
if (brand.isNew) {
brandHtml.push('<i class="icon-hot">HOT</i>');
}
if (brand.isHot) {
brandHtml.push('<i class="icon-new">NEW</i>');
}
brandHtml.push('</a></p>');
});
brandHtml.push('</div>');
html += brandHtml.join('');
});
}
// 插入 dom,绑定事件
$('.search-result').html(html);
... ... @@ -118,7 +121,6 @@ if ($('.brand-search-page').length) {
$keyword.on('input', function() {
if ($keyword.val().length) {
searchResult();
$icon.css('color', '#000');
$(this).closest('.search-box').css('width', '11.25rem');
$('.search-action').show();
... ... @@ -127,6 +129,7 @@ if ($('.brand-search-page').length) {
$(this).closest('.search-box').css('width', '12.5rem');
$('.search-action').hide();
}
searchResult();
}).focus();
clearTextHammer = new Hammer($('.clear-text')[0]);
... ...