douzi2778 2016-01-16 05:45
浏览 143

MagicSuggest依赖多个下拉菜单无法正常工作

I am using MagicSuggest for custom dropdown, now I have two dropdowns category and sub category.. sub categories should be populated based on category selection. When I select category, and then subcategory, it will work for the first time, but if I change the category sub categories will not change and shows the same list. here is my jquery..

var cat = $('#category').magicSuggest({
    maxSelection:1,
    data: site+'project/getCats/',
    valueField: 'id',
    displayField: 'title',
    mode: 'remote',
    renderer: function(data){
        return '<div>' +
                '<div class="title">' + data.title + '</div>' +
            '</div>';
    },
    resultAsString: true,
    selectionRenderer: function(data){
        return '<div class="name">' + data.title + '</div>';
    }
});
$(cat).bind('selectionchange', function(event, combo, selection){
    cat_id = cat.getValue();
    src = site+'project/getCats/'+cat_id;
    var subcat = $('#sub_category').magicSuggest({
        maxSelection:1,
        data: src,
        valueField: 'id',
        displayField: 'title',
        mode: 'remote',
        renderer: function(data){
            return '<div>' +
                    '<div class="title">' + data.title + '</div>' +
                '</div>';
        },
        resultAsString: true,
        selectionRenderer: function(data){
            return '<div class="name">' + data.title + '</div>';
        }
    });
})
  • 写回答

1条回答 默认 最新

  • doujia3441 2016-08-25 07:33
    关注

    Since no one is replying I will take the risk..

    Taken from Magicsuggest home page http://nicolasbize.com/magicsuggest/doc.html.

    I think you need to use the setData() which sets the objects listed in the combo.

    var ms = $('#ms-setData').magicSuggest({});
    ms.setData(['Paris', 'New York', 'Gotham']);
    $(ms).on('selectionchange', function(){
        alert(JSON.stringify(this.getSelection()));
        this.setData([
            {id:1, name:'Blue'},
            {id:2, name:'Red'}
        ]);
    });
    

    If you go to the link I posted above, you will find a working example. You first choose a city eg Paris and then the options are changed in colors so you can select blue.

    You can tweak your code to use the setData on the "sub_category"..

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化