Titanium JIRA Archive
Appcelerator Community (AC)

[AC-1556] Instance Model-View Binding dataTransform attributed ignored

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionInvalid
Resolution Date2014-04-23T03:27:30.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsAlloy
Labelsn/a
ReporterAntonio Calanducci
AssigneeRitu Agrawal
Created2014-04-08T20:29:58.000+0000
Updated2016-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

FileDateSize
app.zip2014-04-08T20:29:58.000+00005903321

Comments

  1. Tim Poulsen 2014-04-17

    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:
       $.aPerson.on('change', function(model){
          $.fullname.text = model.attributes.name + " " + model.attributes.surname;
       });
       
    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.
  2. Ritu Agrawal 2014-04-23

    Resolving this ticket as invalid as transforms on a bound model like this aren't supported.

JSON Source