brand-relation.js 1.7 KB
var $ = require('jquery'),
	common = require('../../common/common');

/*common.util.__ajax({
	url: '/goods/brands/queryBrandsByStatus'
}, function(res) {
	//console.log(res);
	var data = res.data;

	var html = '',
		brandHtml = '';
	var aLif = null;
	$.each(data, function(i, value) {
		//console.log(aLif, value.brandAlif);
		aLif = value.brandAlif;
		if (aLif != value.brandAlif) {
			aLif = value.brandAlif;
			html += '<div class="col-sm-2">' + aLif + '</div>';
			brandHtml += '<div class="col-sm-10"><label><input tyoe="checkbox" value="' + value.id + '">' + value.brandName + '</label>';
		} else {
			brandHtml += '<label><input tyoe="checkbox" value="' + value.id + '">' + value.brandName + '</label>';
		}

	});

	//$('.brand-list').html(html + brandHtml);
}, true);*/

var data = [{
	brandName: 'aaa',
	a: 'A',
	id: 1
}, {
	brandName: 'abb',
	a: 'A',
	id: 3
}, {
	brandName: 'bbb',
	a: 'B',
	id: 2
}];

var firstName = null,
	map = {},
	rowHtml = '',
	rowHtmlH = '',
	rowHtmlB = '';


$.each(data, function(i, item) {
	if (item.a) {
		/*console.log(firstName, value.a);
		if (firstName != value.a) {

			firstName = value.a;
			/*rowHtmlH = '';
			rowHtmlB = '';
			rowHtml += rowHtmlH + rowHtmlB + '</div>';
			rowHtmlH += '<div class="col-sm-2">' + firstName + '</div>';

			rowHtmlB += '<div class="col-sm-10><label><input tyoe="checkbox" value="' + value.id + '">' + value.brandName + '</label>'

		} else {
			rowHtmlB += '<label><input tyoe="checkbox" value="' + value.id + '">' + value.brandName + '</label>';
		}*/

		if (!map.hasOwnProperty(item.a)) {
			map[item.a] = [];
		}
		map[item.a].push(item);

	}
});

console.log(map);


$('.brand-list').html(common.util.__template2($('#brandTemp').html(), {
	map: map
}));