黄舟2017-04-10 16:00:021楼
@foreach (var category in Model.Categories)
{
//-这里循环开始,比如Model.Categories里面有3组数据
@(index)F @category.Name
@foreach (var ca in category.SubCategories)
{
}
//-- 这里是下面的内容
@foreach (var subca in category.SubCategories)
{
}
index++;
}
$(document).ready(function () {
/*首页的分类产品数据 */
homePageCategoriesInTabs();
$('.home-page-category-tabs .home-page-category-anchor').first().click();
});
function homePageCategoriesInTabs() {
if ($('.home-page-category-tabs').length == 0) {
return;
}
var getProductsUrl = $('.home-page-category-tabs').attr('data-get-products-url');
if (typeof getProductsUrl == 'undefined' || getProductsUrl == '') {
return;
}
$('.home-page-category-tabs .home-page-category-anchor').on('click', function () {
var currentThis = $(this);
var categoryId = currentThis.attr('data-category-id');
if (typeof categoryId == 'undefined' || categoryId == '' || categoryId == '0') {
return;
}
var categoryContentElement = $('.home-page-category-tabs .home-page-category-content[data-category-id="' + categoryId + '"]');
if (categoryContentElement.length == 0) {
return;
}
var isAlreadyLoaded = currentThis.attr('data-is-already-loaded');
if (typeof isAlreadyLoaded == 'undefined' || isAlreadyLoaded != 'true') {
currentThis.attr('data-is-already-loaded', 'true');
//$('.home-page-category-tabs .ajax-loading-overlay1').addClass('active');
$.ajax({
cache: false,
type: 'POST',
data: {
'id': categoryId
},
url: getProductsUrl
}).done(function (data) {
if (data.trim().length == 0) {
data = '
' + '@T("SevenSpikes.Themes.Urban.HomePageCategories.NoProductsFound")' + '
';}
categoryContentElement.html(data);
// Show the selected tab, when its content is loaded
currentThis.parent().addClass('active').siblings().removeClass('active');
categoryContentElement.addClass('active').siblings('.home-page-category-content').removeClass('active');
// Ajax Cart for the selected tab
if (typeof nopAjaxCart !== "undefined" && nopAjaxCart.replaceAddToCartButtonsExternal !== undefined) {
nopAjaxCart.replaceAddToCartButtonsExternal();
}
// Quick View for the selected tab
if (typeof GetProductSelector !== "undefined" && typeof GetQuickViewButtonParentSelector !== "undefined" && typeof AddQuickViewButtons !== "undefined") {
var productSelector = GetProductSelector();
if (productSelector == "") {
return;
}
var quickViewButtonParentSelector = GetQuickViewButtonParentSelector(productSelector);
AddQuickViewButtons(productSelector, quickViewButtonParentSelector);
}
// Product Ribbons for the selected tab
if (typeof nopProductRibbons != "undefined" && nopProductRibbons.showRibbons != undefined) {
nopProductRibbons.showRibbons();
}
}).always(function () {
$('.home-page-category-tabs .ajax-loading-overlay').removeClass('active');
$('.home-page-category-tabs').trigger('homePageCategoriesProductsLoaded');
});
} else {
currentThis.parent().addClass('active').siblings().removeClass('active');
categoryContentElement.addClass('active').siblings().removeClass('active');
}
});
}