-
Notifications
You must be signed in to change notification settings - Fork 191
Data Bindings
Aditya Sharat edited this page Feb 10, 2016
·
1 revision
- Simple Data Bindings
Simple Data Bindings are attribute values which start with $
and are followed by a valid data path.
For example: If you want to bind the user's name to a TextView
where the data path is user.profile.name
you can do the following:
{
"type": "LinearLayout",
"orientation": "vertical",
"children": [
{
"type": "TextView",
"text": "$user.profile.name"
},
{
"type": "ImageView",
"src": "$user.profile.imageUrl"
}
]
}
- Complex Data Bindings
Complex Data Bindings are attribute values that start with ~
. The data paths must be wrapped inside double curly braces {{<data-path>}}
. You can have multiple data paths inside a complex data binding.
For example: "~Rs. {{product.price.value}}"
and "~ Hi {{user.profile.firstName}} {{user.profile.lastName}}"
{
"type": "RelativeLayout",
"children": [
{
"type": "TextView",
"text": "~Achievements - {{user.meta.achievements}}/{{data.totalAchievements}}",
}
]
}
- Complex Data Bindings with Formatters
You can use Formatters
with complex data bindings like this {{<data-path>}}$(<name-of-formatter>)
.
For example: "~ Rs. {{product.price.value}}$(number)"
The output will be be: Rs. 29,899