【问题标题】:Selecting rows from a multiselect从多选中选择行
【发布时间】:2014-03-14 22:30:37
【问题描述】:

我有一个 html <select id="nr_s_actors"> DOM 对象。在<select> 内部,我有许多不同的<option>s 标签,它们的ID 不同。如何设置它们被选中?

我通过调用代码将我的 <select> 对象变成了一个精美的 jQuery multiselect $("#nr_s_actors").multiselect(); 所有这些都可以正常工作(视觉上),但我无法设置它的选定选项并让它不再视觉显示。

下面是我的 ajax json 调用。我正确地取回了我的数据,并且名为 id 的 var 是正确的。我的选项的 id 是“id_actor_X”,其中 X 是一个数字。 (我从参数value[0]得到)

$.ajax(
 { 
    url: 'phpscripts/getreportrelations.php', 
    data: 'reportid=' + aData[0], 
    dataType: 'json', 
    success: function(data) 
    {
        $.each(data,function(index,value)
        {
                var id="id_actor_"+value[0];
                //Assume the var id is correctly set to the id of the option. 

                //what goes here?
        });
    },
    error: function (header, status, error) 
    {
        console.log('ajax answer post returned error ' + header + ' ' + status + ' ' + error);
    }
});

【问题讨论】:

  • 你应该添加你的 html / js 代码。
  • 谢谢!事实证明,我只需要 $("#nr_s_actors").multiselect("refresh");

标签: jquery html ajax json multi-select


【解决方案1】:

试试这样的:

    $.each(data,function(index,value)
    {
            var id="id_actor_"+value[0];
            //Assume the var id is correctly set to the id of the option. 
            $("#"+id).prop("selected", true);
    });
    $("#nr_s_actors").multiselect("refresh");

【讨论】:

    猜你喜欢
    • 2011-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-16
    • 2021-05-20
    • 1970-01-01
    • 2015-07-24
    相关资源
    最近更新 更多