设置单击默认为

时间:2016-07-04 16:35:29

标签: javascript jquery sharepoint-2013 filtering

我正在使用Megafolio所以现在我使用clic过滤类别,但我想在页面加载时设置默认类别,我该怎么做?

有我的过滤功能

function completeGalleryContent(data, target, eng) {
var items = data.d.results;
console.log(items);
var menu = "";
var cat = "";
for (var item in items) {
if(items[item].DescriptionEnglish==null)
    items[item].DescriptionEnglish="";
if(items[item].Description==null)
    items[item].Description="";
    if(items[item].Categoria.results!= null && items[item].Categoria.results!= undefined && items[item].Categoria.results.length > 0){
        cat =setCategories(eng,items[item].Categoria.results);
    }
    if (eng){

        menu += "<div class='mega-entry " + cat + " cat-all' id='mega-entry-1' data-src='" + items[item].EncodedAbsUrl + "' data-width='' data-height='' data-lowsize=''><div class='mega-covercaption mega-square-bottom mega-landscape-right mega-portrait-bottom mega-red'><div class='mega-title'>" + items[item].TitleEnglish + "</div><p>" + items[item].DescriptionEnglish + "</p></div><div class='mega-coverbuttons'><div class='mega-link mega-red'></div><a class='fancybox' rel='group' href='" + items[item].EncodedAbsUrl + "' title='" + items[item].TitleEnglish + "'><div class='mega-view mega-red'></div></a></div></div>";
    }else{
        menu += "<div class='mega-entry "+ cat + " cat-all' id='mega-entry-1' data-src='" + items[item].EncodedAbsUrl + "' data-width='' data-height='' data-lowsize=''><div class='mega-covercaption mega-square-bottom mega-landscape-right mega-portrait-bottom mega-red'><div class='mega-title'>" + items[item].Title + "</div><p>" + items[item].Description + "</p></div><div class='mega-coverbuttons'><div class='mega-link mega-red'></div><a class='fancybox' rel='group' href='" + items[item].EncodedAbsUrl + "' title='"+ items[item].Title +"'><div class='mega-view mega-red'></div></a></div></div>";
    }
 }
 $(target).html(menu);
  var api = $(target).megafoliopro(
                {
                    filterChangeAnimation: "pagebottom",            // fade, rotate, scale, rotatescale, pagetop, pagebottom,pagemiddle
                    filterChangeSpeed: 400,                 // Speed of Transition
                    filterChangeRotate: 99,                 // If you ue scalerotate or rotate you can set the rotation (99 = random !!)
                    filterChangeScale: 0.6,                 // Scale Animation Endparameter
                    delay: 20,
                    defaultWidth: 980,
                    paddingHorizontal: 10,
                    paddingVertical: 10,
                    layoutarray: [9, 11, 5, 3, 7, 12, 4, 6, 13]     // Defines the Layout Types which can be used in the Gallery. 2-9 or "random". You can define more than one, like {5,2,6,4} where the first items will be orderd in layout 5, the next comming items in layout 2, the next comming items in layout 6 etc... You can use also simple {9} then all item ordered in Layout 9 type.
                });

        //console.log("entra");
        // FANCY BOX ( LIVE BOX) WITH MEDIA SUPPORT
        jQuery(".fancybox").fancybox();
        //console.log("sale");

        // THE FILTER FUNCTION
        $('.filter').click(function () {
            $('.filter').each(function () { jQuery(this).removeClass("selected") });
            api.megafilter(jQuery(this).data('category'));
            $(this).addClass("selected");
        });
 var categorySelected = getParameterByName("Category");

$("div[data-category='"+categorySelected +"']").click();

 }

我尝试改变这些行,但不起作用:

var categorySelected = getParameterByName("Office"); 

或类似

var categorySelected = getParameterByName().first;

首先填充db

1 个答案:

答案 0 :(得分:2)

使用jQuery,您可以使用click()函数:

$(document).ready(function(){
    $('[href="#first_steps"]').click();
});

如果需要,可以通过其他链接更改first_steps。

修改

使用数据类别:

$('[data-category="Office"]').click(); // An html attribute with value