Authored by biao

fix subnav bug

... ... @@ -12,9 +12,12 @@ exports.index = (req, res) => {
headerModel.getHeaderData()
.then(function(modelRes) {
let response = JSON.parse(modelRes);
let data = headerModel.getAllHeaderData(response.data);
let data = headerModel.getAllHeaderData(response.data, 'boy');
data.headerData.navbars[0].active = true;
console.log(data.headerData.subNav);
res.render('index', data);
})
.catch(function(err) {
... ...
... ... @@ -135,10 +135,27 @@ const getThirdNav = (data) => {
* @param undefined
* @return {array} 子菜单数组
*/
const getSubNav = (data) => {
const getSubNav = (data, type) => {
let subNav = [];
_.forEach(data, function(item) {
let index = 0;
switch(type) {
case 'boy':
index = 0;
break;
case 'girl':
index = 1;
break;
case 'kids':
index = 2;
break;
case 'lifestyle':
index = 3;
break;
}
_.forEach(data[index].sub, function(item) {
let obj = {};
obj.link = item.sort_url;
... ... @@ -151,7 +168,8 @@ const getSubNav = (data) => {
}
subNav.push(obj);
});
})
return subNav;
};
... ... @@ -162,15 +180,15 @@ const getSubNav = (data) => {
* @param {object} 接口返回的对象
* @return {object} 头部数据
*/
exports.getAllHeaderData = function(resData) {
exports.getAllHeaderData = function(resData, type) {
let config = getConfig();
let data = {
headerData: {
header: true,
type: 'boy',
type: type,
yohoGroup: getMenuData(),
navbars: getNavBar(resData),
subNav: getSubNav(resData)
subNav: getSubNav(resData, type)
}
};
... ...