Jquery 完整日历过滤器 - 不完全理解声明

Jquery Full Calendar Filter - Not Fully Understanding A Statement

我从这个 post 中找到了我需要的东西,但不完全理解为什么我不能更改以下声明:

return ['all', event.school].indexOf($('#school_selector').val()) >= 0

使用以下方法查找 select 的显示文本值:

return ['all', event.EventType].$("#TypeList option:selected").text() !== '';

当 运行 而我的声明时,我对日历网格一无所获(仅获取 header)。似乎遵循相同的逻辑,如果 selected 文本不是 'blank',return 为真,则对 X.

进行排序

我目前正在使用日历示例代码中的静态演示事件,同时我正在处理这个过滤器问题。我看到了其他一些这样做的方法,包括删除和添加事件源,但这似乎更容易、更快(没有所有往返)过滤。

谢谢,

戴夫

你需要这样写:

return ['all', event.EventType].indexOf($("#TypeList option:selected").text()) >= 0

由于您似乎无法理解语法,让我们写下这个:

var event = { "EventType": "XYZ" }; //dummy event data

var arr = ['all', event.EventType]; //an array, which now contains two items = "all" and "XYZ"

var selectedText = $("#TypeList option:selected").text(); //let's assume the selected text is "XYZ"

var locatedIndex = arr.IndexOf(selectedText); //return the index where "XYZ" appears in the array, if any. As we can see, it should return 1, as it matches the item at the 2nd index (arrays being zero-indexed)

//now check whether the index was 0 or more (i.e. we found the item. It will output -1 if it didn't find it). 
//If we found it, return true. If not, return false.
if (locatedIndex >= 0) { return true; }
else { return false; }

我希望这有助于理解该语句的实际作用。