[ALOY-639] Support data-binding for other than Backbone collections
GitHub Issue | n/a |
---|---|
Type | New Feature |
Priority | High |
Status | Open |
Resolution | Unresolved |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Models, Runtime |
Labels | alloy, data-binding |
Reporter | Fokke Zandbergen |
Assignee | Feon Sua Xin Miao |
Created | 2013-04-23T09:13:00.000+0000 |
Updated | 2015-11-27T02:57:10.000+0000 |
Description
This issue was part of ALOY-504 but now separated.
Now we have the
dataFunction
attribute in place, we can manually trigger updating a data-bound view. This issue takes it a step further and asks for the generated data-function to be able to work with general objects/arrays.
index.xml
<TableView dataFunction="fillTable" dataTransform="transformItem" dataFilter="filterData">
<TableViewRow title="{title}" />
</TableView>
index.js
function filterData(data) {
return _.where(data, { title: 'Two' });
}
function transformItem(item) {
var transform = _.clone(item);
transform.title = title + ' ' + _.random(1, 10);
return transform;
}
fillTable([
{ title: 'One' },
{ title: 'Two' },
{ title: 'Three' }
]);
generated data-funtion
function fillTable(data) {
// Apply filter on passed data instead of a collection
var models = dataFilter(data);
// remove existing stuff like normal
// Use Underscore's each instead of a for-loop
_.each(data, function (_alloyId*N*) {
// Apply transform on item like normal
_alloyId*N*.__transform = dataTransform(_alloyId*N*);
// Generate and add views like normal
}
}
Some notes:
* The dataTransform
and dataFilter
implementations won't need to be changed since the user is responsible for what happens inside these functions and the input and output when called on regular objects would be exactly the same.
* The generated data-function would need to accept an object/array as argument.
* The generated data-function would need to use _.each
instead of a for-loop, because it needs to support any loop-able data.
* In case a dataCollection
attribute was specified, the first line in the generated data-funtion could be changed to var models = dataFilter(data || _alloyId*N*);
so the data-function would both work on the bound collection as well as manually called with custom data.
Thanks for changing this to high priority... still 'd like this very much ;)
I also like to have it - see my question: https://developer.appcelerator.com/question/180238/howto-fire-event-to-refresh-view