Uploaded image for project: 'Alloy'
  1. Alloy
  2. ALOY-1368

Complex data binding for individual model doesn't work with transform() method

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: alloy 1.7.35
    • Fix Version/s: alloy 1.8.3, Release 5.2.2
    • Component/s: Models, XML
    • Labels:
      None
    • Environment:

      Alloy 1.7.35

    • Story Points:
      5
    • Sprint:
      2016 Sprint 07 Tooling

      Description

      The complex data binding introduced by ALOY-443 does not work if the model has a transform() method:

      <Alloy>
      	<Model src="user" />
      	<Window>
      		<Label title="{user.foo}" />
      		<Label title="the {user.foo}" />
      		<Label title="{user.foo} - {user.bar}" />
      	</Window>
      </Alloy>
      

      Compiles to:

          var __alloyId13 = function() {
              $.__alloyId2.title = _.isFunction(Alloy.Models.user.transform) ? Alloy.Models.user.transform()["foo"] : _.template("<%=user.foo%>", {
                  user: Alloy.Models.user.toJSON()
              });
              $.__alloyId3.title = _.isFunction(Alloy.Models.user.transform) ? Alloy.Models.user.transform()["foo"] : _.template("the <%=user.foo%>", {
                  user: Alloy.Models.user.toJSON()
              });
              $.__alloyId4.title = _.isFunction(Alloy.Models.user.transform) ? Alloy.Models.user.transform()["foo"] : _.template("<%=user.foo%> - <%=user.bar%>", {
                  user: Alloy.Models.user.toJSON()
              });
          };
      

      So, if the model has a transform() method all three labels will only show the value of the foo attribute.

      The correct code should be:

          var __alloyId13 = function() {
              var transformed = _.isFunction(Alloy.Models.user.transform) ? Alloy.Models.user.transform() : Alloy.Models.user.toJSON();
              $.__alloyId2.title = _.template("<%=user.foo%>", {
                  user: transformed
              });
              $.__alloyId3.title = _.template("the <%=user.foo%>", {
                  user: transformed
              });
              $.__alloyId4.title = _.template("<%=user.foo%> - <%=user.bar%>", {
                  user: transformed
              });
          };
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                fokkezb Fokke Zandbergen
                Reporter:
                fokkezb Fokke Zandbergen
                Reviewer:
                Feon Sua Xin Miao
                Tester:
                Harry Bryant
              • Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

                  • Backbone Issue Sync is enabled for your project, but we do not have any synchronization info for this issue.

                    Git Integration