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

Widget/Require as top-level element uses controller as view

    Details

      Description

      When a controller-view has a widget or require as a root element, the compiled code will use the required controller as the view, as seen in the following example:

      index.xml

      <Alloy>
        <Widget src="foo" />
      </Alloy>
      

      widget.xml

      <Alloy>
        <Window>
          <Label>I'm the default widget</Label>
        </Window>
      </Alloy>
      

      index.js (compiled)

      //..
          $.__views.index = Alloy.createWidget("foo", "widget", {
              id: "index"
          });
          $.__views.index && $.addTopLevelView($.__views.index);
      //..
      

      console

      [ERROR] TypeError: undefined is not a function (evaluating '$.index.open()')
      [ERROR] File: app.js
      [ERROR] Line: 33
      [ERROR] SourceId: <null>
      [ERROR] Backtrace:
      [ERROR]  undefined
      

      index.js (expected)

      //..
          $.__views.index = Alloy.createWidget("foo", "widget", {
              id: "index"
          });
          $.__views.index && $.addTopLevelView($.__views.index.getView());
          // OR: $.__views.index && $.addTopLevelView($.__views.index.getViewEx({recurse:true}));
      //..
      

      Found via this GitHub ticket, which includes a link to a full example:
      https://github.com/FokkeZB/nl.fokkezb.pullToRefresh/issues/39

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                bhouse Brenton House
                Reporter:
                fokkezb Fokke Zandbergen
                Reviewer:
                Ewan Harris
                Tester:
                Samir Mohammed
              • Watchers:
                6 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