brand-relation.js
1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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
}));