【问题标题】:Jquery Full Calendar Filter - Not Fully Understanding A StatementJquery Full Calendar Filter - 不完全理解语句
【发布时间】:2019-04-15 11:17:01
【问题描述】:

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

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

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

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

当我的语句运行时,我没有得到日历网格(仅获取标题)。似乎遵循相同的逻辑,如果所选文本不是“空白”,则返回 true,并为 X 排序。

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

谢谢,

戴夫

【问题讨论】:

  • 你想做什么?那里的语法错误。
  • [] 是一个数组对象。数组上没有继承 $ 属性。还是您打错字并从第二个 sn-p 中删除了 indexOf() 调用。
  • 不,我是故意取出 IndexOf 的,因为我不是真的在寻找索引,而是在寻找显示的文本。这也是我认为a [] 是一个数组,但也看到a [],是一个选择[x , y] 如果为真则返回x,否则返回y。
  • @Dekel,我正在尝试按下拉列表中的文本而不是选项标签中的值对事件进行排序。我想我可以在选项中添加 value = 'x' 。但我确实明白我的语法是关闭的。
  • 如果我在选项标签中使用“值”,它会很好用。所以现在想知道为什么我不能或如何使用选择框中的文本。对我来说很奇怪,仍在尝试掌握 Jquery 和 JavaScript。

标签: javascript jquery arrays fullcalendar indexof


【解决方案1】:

你需要这样写:

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

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

【讨论】:

  • 好的,我知道我的想法错在哪里,我认为“IndexOf”是下拉菜单的,但它是 All 或 Event Type 的数组。这有点巧妙,它是如何一步完成的,而不是 10 =)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-01-13
  • 2013-06-15
  • 1970-01-01
  • 2018-05-13
  • 1970-01-01
  • 2017-07-24
  • 2012-04-29
相关资源
最近更新 更多