Sometimes you need to concatenate two values together to create a displayed value. Or perhaps you want to perform a calculation based on the combination of two or more values. We've been using the term expression part casually, but now you'll see that they can be combined to make a full runtime expression.

Complex expressions are very powerful. With them you can mix and match most expression types (#bind, #get, #param, #res), but there are some limitations you should be aware of.

  • Complex expressions containing #bind are one way
  • One side effect of using complex expressions is that any bindings become one-way. In other words, if you were to do this:

        <j:TextBox text="#bind(item.firstName) + ' ' + #bind(item.lastName)"/>
        

    The text box will be set to the right value initially. However, any user edits will not be propagated back to the dataset - that's because Jitsu doesn't know how to invert a JavaScript expression.

    In practice, almost all expression bindings are for presenting output, so this is rarely an issue.

  • Expressions may not mix and match #bind with other expression parts
  • You may mix and match any of the static expression parts, like #get and #res, and you may combine multiple #bind parts, but you may not combine the two. [TODO: this is an arbitrary restriction, imposed by vestigial implementation. Should be fixed.]

    Bindings in JavaScript event handlers

    You can use the #get and #set expression parts in an event handler to either get or set the value of a binding path associated with the current control, e.g.:

            <j:Button text="Increment"
                    click="#set(item.age) = #get(item.age) + 1;"/>
        

    Clicking on this button increments the person's age by one.