基于控制器值在jquery中解包列表项 [英] unwrap list items in jquery based on controller value

查看:84
本文介绍了基于控制器值在jquery中解包列表项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个侧边菜单。每个菜单在无序列表下都有作为列表项的子项,如

I have two side menus. Each menu has subitems as list items under unordered list, like

 - FIRST MENU
    - Link one
    - Link two

 - SECOND MENU
    - Link three
    - Link four

当页面加载时,我想打开一个菜单,其他菜单列表项应该保持打开
like

When page loads I want to open one menu and other menu list items should stayed unwrapped like

- FIRST MENU
    - Link one
    - Link two

 - SECOND MENU

我在FIRST MENU的工作示例中解开了此处但我需要展开第二个菜单的示例,所以我可以更改为从我的控制器发送的动态值。

I have working example with FIRST MENU unwrapped here but I do need example with unwrapped SECOND MENU so I can change it to dynamic value sent from my controller.

var unwrapped_menu = $ data_sent_from_controller;
if data_sent_from_controller ==SECOND MENU
然后打开第二个菜单。

var unwrapped_menu = $data_sent_from_controller; if data_sent_from_controller == "SECOND MENU" then unwrapped second menu.

更改此示例这里到硬编码的SECOND MENU解包将是完美的。而已。

Changed this example here to hardcoded SECOND MENU unwrapped would be perfect. Nothing more.

如果您需要更多信息,请问。

If you need more info please ask.

推荐答案

从控制器发送的动态值是要打开的菜单的索引(从0开始):

If the dynamic value sent from the controller is the index (starting from 0) of the menu to be opened then:

JSFIDDLE

dynamic_value_from_controller = 1;

$(document).ready(function() {
    $.easing.def = "easeOutBounce";

    var menus = $( 'div.menu ul li.submenu' ),
        current_submenu = null;
    menus.next().hide();
    menus.each( function(i){
        var dropdown = $( this ).next(),
            title = $( 'a.title', this );
        title.click( function(e){
            if ( current_submenu !== null && current_submenu != dropdown )
            {
                current_submenu.slideUp( 'slow' );
            }
            current_submenu = dropdown;
            dropdown.stop(false, true).slideToggle('slow');
            e.preventDefault();
        } );
        if ( i == dynamic_value_from_controller )
            title.click();
    });
});

如果动态值是标题的文本,则:

If the dynamic value is the text of the title then:

JSFIDDLE

dynamic_value_from_controller = 'SECOND MENU';

$(document).ready(function() {
    $.easing.def = "easeOutBounce";

    var menus = $( 'div.menu ul li.submenu' ),
        current_submenu = null;
    menus.next().hide();
    menus.each( function(i){
        var dropdown = $( this ).next(),
            title = $( 'a.title', this );
        title.click( function(e){
            if ( current_submenu !== null && current_submenu != dropdown )
            {
                current_submenu.slideUp( 'slow' );
            }
            current_submenu = dropdown;
            dropdown.stop(false, true).slideToggle('slow');
            e.preventDefault();
        } );
        if ( title.text() == dynamic_value_from_controller )
            title.click();
    });
});

这篇关于基于控制器值在jquery中解包列表项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆