brand-render.js 875 Bytes

var $ = require('yoho-jquery'),
    dbClass = 'data-bind';

module.exports = function(callback) {
    $.ajax({
        type: 'POST',
        url: '/brands/searchAsync',
        success: function(data) {
            render(data.data);
            callback && callback(data);
        }
    });
};
function render(data) {
    if (data.history && data.history.list && data.history.list.length) {
        var hisEl = $('.history>li').remove();
        $.each(data.history.list, function(i, his) {
            var itemEl = hisEl.clone();
            itemEl.find('a')
            .attr('href', his.url)
            .attr('brandName', his.name)
            .attr('collectTime', his.searchTime)
            .text(his.name);
            $('.history').append(itemEl);
        });
        $('.net-history').removeClass(dbClass);
    } else {
        $('.net-history').remove();
    }
}