首页 > 解决方案 > Fullcalendar 从 3.x 迁移到 4.x extraParams 不会将多个输入作为数组操作

问题描述

我正在尝试从 fullcalendar 3.x 迁移到 4.x

<select id="ids" name="ids[]" class="form-control" multiple>
 <option value="1" selected> Option 1</option>
 <option value="2"> Option 2</option>
 <option value="3"> Option 3</option>
</select>

<button type="button" id="btn-filter">Apply</button>

在 3.x 版本中,data里面的参数events被正确地管理为数组:

这是我的 Firefox 控制台:

array_ids[]:
    0: 1
    1: 2
start:  2019-06-01T00:00:00
end:    2019-07-01T00:00:00

一段代码:

  events: {
        url: './get-events.php',
        cache: false,
        type: 'POST',
        data: function() { // a function that returns an object
          return {
            array_ids: $("#ids").val()
           };
        }
        error: function () {
            alert('there was an error while fetching events!');
        },
    },

现在使用此代码转换为 4.x 后:

         events: {
            url: './get-events.php',
            cache: false,
            method: 'POST',      <--- type -> method
            extraParams: function() { 
              return {
                array_ids: $("#ids").val()
              };
            }
        },

我的 Firefox 控制台显示:

array_ids: 1,2             //as string

见附件(本例中array_ids被重命名但逻辑相同) 在此处输入图像描述

标签: javascriptajaxfullcalendarfullcalendar-4

解决方案


推荐阅读