【问题标题】:Select2 - Get data from a loopSelect2 - 从循环中获取数据
【发布时间】:2017-10-31 09:58:46
【问题描述】:

我有一个表格,每一行都包含一个 select2,我想从每个表格中获取数据并将其存储到数组中。下面是我将使用的代码,不确定它是否正确。

// event on each form change re-get the values
         $("#main").bind("keyup change", function (e) {


                        $('#form > tbody  > tr').each(function (i) {

        // get the data for each select
        // add it to array and use after loop for some logic
        // not sure if need this event here : select2:select
        // also the selector might be not in the node of current tr?

                            $('.selector').on("select2:select", function (e) {

                                var data = $(this).select2('data');

                               // push to array ?? data[0].custom_data

                            });

                        });

    // logic from array would be here

                    });

【问题讨论】:

  • 你是否运行了这段代码,如果是,你得到了什么错误?更多细节会有所帮助
  • 好吧,我只有一行:]

标签: jquery jquery-select2 jquery-select2-4


【解决方案1】:

你必须在tr中找到需要的元素

替换

$('.selector').on("select2:select", function (e) {

                            var data = $(this).select2('data');

                           // push to array ?? data[0].custom_data

                        });

var data = $(this).find('.selector').select2('data');

【讨论】:

  • 是的,我想是的
猜你喜欢
  • 1970-01-01
  • 2018-06-04
  • 1970-01-01
  • 2018-12-22
  • 1970-01-01
  • 1970-01-01
  • 2018-03-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多