0

I found what I need from this post but not fully understanding why i cannot change the statement of:

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

to look for the displayed text value of the select using:

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

When ran while my statement, I get nothing for a calendar grid (get the header only). Seems like followed the same logic, if the selected text is not 'blank', return true, and sort for X.

I am current using the static demo events from the calendar sample code, while I am working on this filter issue. I seen some other ways of doing this, with removing and adding the event sources, but this seems like an easier, and quicker (without all the round trips) of filtering.

Thanks,

Dave

ADyson
  • 57,178
  • 14
  • 51
  • 63
MaxThrust
  • 137
  • 2
  • 2
  • 9
  • What are you trying to do? The syntax there is wrong. – Dekel Nov 12 '18 at 17:28
  • 2
    `[]` is an array object. There is no inherit `$` property on arrays. Or did you typo and remove the `indexOf()` call from the second snippet. – Taplar Nov 12 '18 at 17:30
  • No I took the IndexOf out on purpose, since I am not really looking for the Index, but rather the displayed text. That is also what I thought that a [ ] is an array, but also seen where a [ ], is a choice [x , y] if true return x, otherwise return y. – MaxThrust Nov 12 '18 at 17:42
  • @Dekel, I am trying to sort the events by the text in the dropdown rather than the value in the option tags. I guess I could just add in the value = 'x' in the option. But I do understand that my syntax is off. – MaxThrust Nov 12 '18 at 17:46
  • It works great, if I use 'value' in the option tags. So now wondering why I cannot or how to make use the text in the select box. Just very odd to me, still trying to grasp Jquery and JavaScript. – MaxThrust Nov 12 '18 at 17:53
  • "also seen where a [ ], is a choice [x , y] if true return x, otherwise return y"...no I think you're thinking of this `(x == true ? "Yes" : "No")` - quite a different syntax. – ADyson Nov 12 '18 at 18:06

1 Answers1

0

You will need to write it like this:

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

Since you appear to be having trouble understanding the syntax, let's write this long-hand:

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

I hope that helps to understand what the statement is actually doing.

ADyson
  • 57,178
  • 14
  • 51
  • 63
  • Ok, I see where my thinking was wrong, I was thinking the "IndexOf" was that of the dropdown, but rather, it is the array of All or Event Type. That is kind of slick, how it works in one step, versus 10 =). – MaxThrust Nov 12 '18 at 18:34