如何将自定义参数传递给FullCalendar事件Feed?

时间:2015-03-25 06:53:19

标签: javascript jquery html fullcalendar

根据FullCalendar docs,可以将参数传递给JSON提要。我想将一些HTML元素值作为参数传递。我不明白为什么,但有些人成功通过,但其他人则没有。 例如,这一个传递:

<select id="ticketsnumber" class="form-control" name="pax">
   <option value="1" selected="selected">1</option>
   <option value="2">2</option>
   <option value="3">3</option>
   <option value="4">4</option>
   <option value="5">5</option>
   <option value="6">6</option>
</select>

但这不是:

<select id="optionsfrom" class="form-control" name="depplace">
   <option value="" selected="">Откуда...</option>
   <option class="bold info" name="Country" value="460">Россия</option>
   <option name="City" value="1">Москва (MOW)</option>
   <option class="bold info" name="Country" value="359">Болгария</option>
   <option name="City" value="539">ВАРНА ()</option>
   <option class="bold info" name="Country" value="359">Болгария</option>
   <option name="City" value="559">СОФИЯ ()</option>
   <option class="bold info" name="Country" value="84">Испания</option>
   <option name="City" value="19">Барселона (BCN)</option>
   <option class="bold info" name="Country" value="7">США</option>
   <option name="City" value="95">Нью-Йорк (N.Y)</option>
   <option class="bold info" name="Country" value="53">Тайланд</option>
   <option name="City" value="220">Бангкок (BKK)</option>
</select>

这就是我调用事件Feed的方式:

         eventSources: [
                {
                    url: "@Url.Content("~/Home/GetQuota")",
                    data: {
                        pax: $("select[name='pax'] option:selected").val(),
                        fromtype: $("select[name='depplace'] option:selected").attr("name"),
                        fromcode: $("select[name='depplace'] option:selected").val(),
                        totype: $("select[name='arrplace'] option:selected").attr("name"),
                        tocode: $("select[name='arrplace'] option:selected").val(),
                        airservice: $("input[name='tariffs']").val()        
                    },
                    type: "POST",
                    error: function () {
                        alert('Ошибка получения квот!');
                    }
                }
            ]

1 个答案:

答案 0 :(得分:3)

您想要的是动态数据参数(2nd from bottom

当初始化fullcalendar而不是每次查询JSON提要时,上面的代码都会获得$("select[name='depplace'] option:selected").val()

url: "@Url.Content("~/Home/GetQuota")",
data: function() { //runs every time the JSON script is called.
    return {
        pax: $("select[name='pax'] option:selected").val(),
        fromtype: $("select[name='depplace'] option:selected").attr("name"),
        fromcode: $("select[name='depplace'] option:selected").val(),
        totype: $("select[name='arrplace'] option:selected").attr("name"),
        tocode: $("select[name='arrplace'] option:selected").val(),
        airservice: $("input[name='tariffs']").val()  
    };
}