繁体   English   中英

jQuery完整日历过滤器-无法完全理解语句

[英]Jquery Full Calendar Filter - Not Fully Understanding A Statement

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

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

使用以下命令查找选择的显示文本值:

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

在我的语句运行时,日历网格没有任何内容(仅获取标题)。 似乎遵循相同的逻辑,如果所选文本不是'blank',则返回true,然后对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; }

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM