0

@converter - is it possible to pass 'format' via MVVM property?

asked 2019-06-13 16:03:18 +0800

davout gravatar image davout
1435 3 18

updated 2019-06-13 16:23:37 +0800

Taking the following example...

<label value="@load(item.price) @converter('formatedNumber', format='###,##0.00')"/>

Is it possible to replace the '###,##0.00' value with a MVVM property? I've tried it and I get a parsing error

Also if I write a custom converter, it is possible to pass extra properties to the custom converter? In my case I want to pass a format string and a scaling factor ( x 1000000).

Something like..... Format = ####,##0.00 Scaling = 1000000

So that an input number of 4,654,654 is displayed as: 4.65

delete flag offensive retag edit

4 Answers

Sort by » oldest newest most voted
0

answered 2019-06-15 17:57:42 +0800

davout gravatar image davout
1435 3 18

Does that work with an array mvvm property? For when I tried ...

Format = vm.cellformat[0]

.... it returned a parsing error

link publish delete flag offensive edit
0

answered 2019-06-14 10:11:30 +0800

hawk gravatar image hawk
2400 1 5
http://hawkphoenix.blogsp... ZK Team
  • pass a vm property to a converter

the attribute in a data binding is EL. format=[EL-expression]

e.g. pass a string

format='aString'

For the data binding syntax, please refer to http://books.zkoss.org/zk-mvvm-book/8.0/syntax/data_binding.html

so you can write like:

<label value="@load(item.price) @converter('formatedNumber', format=vm.format)"/>

  • get arguments in a converter

You can get a parameter by (String) ctx.getConverterArg("format");

please refer to Implement a Converter

link publish delete flag offensive edit

Comments

Does it work within an array property? Because when I set “format=vm.cellformat[0]”. It returned a parsing error.

davout ( 2019-06-15 17:59:55 +0800 )edit

could you show us the complete data binding statement?

hawk ( 2019-06-17 17:01:09 +0800 )edit
0

answered 2019-06-17 17:02:59 +0800

hawk gravatar image hawk
2400 1 5
http://hawkphoenix.blogsp... ZK Team

updated 2019-06-17 17:33:25 +0800

accessing an array with EL is supported, please refer to https://github.com/zkoss/zkbooks/blob/master/mvvmreference/src/main/webapp/databinding/el.zul

link publish delete flag offensive edit
0

answered 2019-06-26 11:34:21 +0800

davout gravatar image davout
1435 3 18

updated 2019-06-26 11:35:37 +0800

I have a grid cell formatting requirement where I need to pass in two parameters:

  • Format (e.g. "#,###.00"); and
  • Scale (e.g. 1, or 1000 or 1,000,000), that allows a large number to be displayed as a smaller number

For example:

  • Number : 3,456,789
  • Format: #,###.00
  • Scale: 1,000,000
  • Output: 3.46
link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2019-06-13 16:03:18 +0800

Seen: 18 times

Last updated: Jun 26

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More