[AC-1556] Instance Model-View Binding dataTransform attributed ignored
| GitHub Issue | n/a |
|---|---|
| Type | Bug |
| Priority | n/a |
| Status | Closed |
| Resolution | Invalid |
| Resolution Date | 2014-04-23T03:27:30.000+0000 |
| Affected Version/s | n/a |
| Fix Version/s | n/a |
| Components | Alloy |
| Labels | n/a |
| Reporter | Antonio Calanducci |
| Assignee | Ritu Agrawal |
| Created | 2014-04-08T20:29:58.000+0000 |
| Updated | 2016-03-08T07:38:01.000+0000 |
Description
dataTransform seems to be ignored at all when instance (or singleton) model attributes are bound to views (the Ti.API info doesn't print anything in the console):
index.html
<Alloy>
<Model src="Person" id="aPerson" instance="true" />
<Window class="container" dataTransform="buildFullName">
<Label text="{$.aPerson.name}" />
<Label text="{$.aPerson.surname}" />
<Label text="{$.aPerson.fullname}" />
</Window>
</Alloy>
index.js
function buildFullName(model) {
Ti.API.info("trasformation has been called");
return {
name: model.attributes.name,
fullname: model.attributes.name + " " + model.attributes.surname,
surname: model.attributes.surname
};
};
$.aPerson.set({
name: "Steve",
surname: "Jobs"});
$.index.open();
Moreover in the code generated by alloy in the index.js I see duplication:
var __alloyId3 = function() {
$.__alloyId0.text = _.isFunction($.aPerson.transform) ? $.aPerson.transform()["name"] : $.aPerson.get("name");
$.__alloyId0.text = _.isFunction($.aPerson.transform) ? $.aPerson.transform()["name"] : $.aPerson.get("name");
$.__alloyId1.text = _.isFunction($.aPerson.transform) ? $.aPerson.transform()["surname"] : $.aPerson.get("surname");
$.__alloyId1.text = _.isFunction($.aPerson.transform) ? $.aPerson.transform()["surname"] : $.aPerson.get("surname");
$.__alloyId2.text = _.isFunction($.aPerson.transform) ? $.aPerson.transform()["fullname"] : $.aPerson.get("fullname");
$.__alloyId2.text = _.isFunction($.aPerson.transform) ? $.aPerson.transform()["fullname"] : $.aPerson.get("fullname");
};
Attachments
| File | Date | Size |
|---|---|---|
| app.zip | 2014-04-08T20:29:58.000+0000 | 5903321 |
Transforms on a bound model like this aren't supported. There is a workaround to accomplish what you're trying to do with your function. Add an id attribute to your full name label. Then, add this to your controller:
Models and collections are going to be reworked in Alloy 2.0. So, this ticket could be a feature request, but it might not get attention until then. As for the duplicated code on output, that should be resolved once we implement the support for dataTransform on models.$.aPerson.on('change', function(model){ $.fullname.text = model.attributes.name + " " + model.attributes.surname; });Resolving this ticket as invalid as transforms on a bound model like this aren't supported.