Skip to Content

Expression Binding for number property of ObjectListItem

Is there a way to set up expression binding on the number property of an Object ListItem?

Here's what it's doing now...

<ObjectListItem
     number="{ path: 'basket>TotalPrice', formatter: '.formatPrice'}"                                              
>

What I need to do is set path depending on the whether {site>/ShowPrices} is true or false..

Is that possiible.

 <ObjectListItem
     number="{ path: = ${site>/ShowPrices} ? 'basket>TotalPrice' : '0', formatter: '.formatPrice'}"                                              
>

E.g show the price if site>/ShowPrices is true, else show 0.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Feb 11, 2017 at 12:45 AM

    You cannot use expression binding to assign a binding . You can either apply complex binding of parts

    <ObjectListItem number="{ parts : [{path: 'basket>TotalPrice'},{ path : 'site>/ShowPrices'}], formatter: '.formatPrice'}">
    

    or

    <ObjectListItem number="{= ${site>/ShowPrices} ? ${basket>TotalPrice} : '0'  }">
    

    Thanks and Regards,
    Veera

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 13, 2017 at 01:13 PM

    in this case its not possible, and as Veera suggested, pass both value in parts and handle and put condition in formatter function as below:

    <ObjectListItem number="{ parts : [{path: 'basket>TotalPrice'},{ path : 'site>/ShowPrices'}], formatter: '.formatPrice'}">

    and formatter:

    formatPrice: function(totalValue, bShowPriceValue){
      var formattedValue = 0;
      if(bShowPriceValue){
       formattedValue = totalValue;
      }
      return formattedValue;
    }

    Hope this help.

    -Akhilesh

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 10, 2017 at 05:51 PM

    Expression binding can set a pre-defined constant values after evaluating the expression. In your case after the expression is evaluated you are setting a model value instead of a constant.

    Possible approach would be formatter only like you did

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 08, 2017 at 04:02 PM

    Thank you. I've need to set the value to 0 in the controller instead.

    Add comment
    10|10000 characters needed characters exceeded