mx.parser
Formatting and parsing functionality for values.
Methods
Converts a value to a string in the requested format.
Parameters
Name |
Type |
Description |
value |
Any |
Value to convert |
type |
String |
The data type as which to interpret value . Can be one of “float”, “currency”, “autonumber”, “integer”, “long”, “datetime”, “boolean”, “binary”, “string”, “hashstring”, “enum”. |
props |
Object |
Parameters passed to dojo.number.format() for number conversions or to dojo.date.locale.format() for date conversions. |
Returns
Type |
Description |
String |
The formatted value |
Example
mx.parser.formatValue(3000, "currency"); // "3000.00"
mx.parser.formatValue(+new Date(1980, 7, 23), "datetime",
{ datePattern: "dd-MM-yyyy" }); // "23-08-1980"
Converts an MxObject attribute to a string in the requested format.
Parameters
Name |
Type |
Description |
obj |
MxObject |
MxObject to fetch the attribute from. |
attr |
String |
Attribute to fetch. |
props |
Object |
Passsed to mx.parser.formatValue as props parameter |
Returns
Type |
Description |
String |
The formatted attribute |
Example
mxobj.set("createdDate", +new Date(1980, 7, 23));
mx.parser.formatAttribute(mxobj, "createdDate",
{ datePattern: "dd-MM-yyyy" }); // 23-08-1980
parseValue(value, type, props)
Converts a string in the given format to a value.
Parameters
Name |
Type |
Description |
value |
String |
String to convert |
type |
String |
The data type as which to interpret value . Can be one of “float”, “currency”, “autonumber”, “integer”, “long”, “datetime”, “boolean”, “binary”, “string”, “hashstring”, “enum”. |
props |
Object |
Parameters passed to dojo.number.parse() for number conversions or to dojo.date.locale.parse() for date conversions. |
Returns
Type |
Description |
Number, String, Date |
The value if the value could be parsed, otherwise NaN for numerical types and null for the datetime type. |
Example
mx.parser.parseValue("3,000.00", "currency"); // 3000
mx.parser.parseValue("23-8-1980", "datetime",
{ datePattern: "dd-M-yyyy" }); // Date(1980, 7, 23)