Expression Binding Behavior

I was following along with the Building in Perspective course and reached the end with everything working properly. I wanted to play around with it a bit by changing if a button is in its primary or secondary style depending on which station was currently selected. So I made an expression binding {view.params.stationNumber}!=1 for the Station 1 button, and everything was working properly in the designer, but nothing was happening in my Perspective session. After playing around a bit, I changed my binding to {view.params.stationNumber}!=“1” which caused it to have no effect in the designer, but now things behave as expected in the session.

Basically, I’m wondering if anyone knows why these two expressions are evaluated differently in the designer and Perspective session. It seems as though the parameter is treated as an integer in the designer and a string literal in the session and I don’t know why.

The Designer and Session don’t evaluate the expression differently. The only time you’d see different results is if view.params.stationNumber has a different value between the two locations.
{view.params.stationNumber}!=1 translates to “The prop is not equal to the INTEGER 1.”
{view.params.stationNumber}!="1" translates to “The prop is not equal to the STRING "1".”

If you’re seeing different behavior, check how you’re supplying the value to view.params.stationNumber. It sounds like you’re expecting a number but encountering a string. So either your code is supplying a string, or you’ve passed parameters via URL, where everything is interpreted as a string. How are you setting view.params.stationNumber}?

1 Like

I was passing stationNumber in as a URL parameter, should have realized that would be a string. Thank you!

1 Like