javascript newb question - snippet that can work from several components

  • 1
  • Question
  • Updated 4 years ago
  • Answered
I've got a snippet I'd like to run from both a row action and page title component. How can I dynamically set the row?

Row Action row var


Page Title Button row var
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb

Posted 4 years ago

  • 1
Photo of Menachem Shanowitz

Menachem Shanowitz

  • 1,074 Points 1k badge 2x thumb
row = arguments[0].hasOwnProperty('item') ? arguments[0].item : arguments[0].row;


This is called a ternary if statement, it checks if arguments[0] contains a property item. If yes it assigns to row arguments[0].item, otherwise it assigns arguments[0].row
(Edited)
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
Cool. Trying to trick me though? Found a typo.


 
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
And it was missing the .row in arguments[0].item :Pat
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
Sweet. Works.
Photo of Menachem Shanowitz

Menachem Shanowitz

  • 1,074 Points 1k badge 2x thumb
It was a typo that I corrected :)