Jquery完整日历筛选器-不完全理解语句



我从这篇文章中找到了我需要的东西,但没有完全理解为什么我不能更改以下语句:

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

要查找选择的显示文本值,请使用:

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

当运行while语句时,我不会得到日历网格的任何内容(只得到标题(。似乎遵循了相同的逻辑,如果所选文本不是"空白",则返回true,并为X.排序

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

谢谢,

Dave

您需要这样写:

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; }

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

最新更新