[ALOY-368] Widgets should reference controllers within their standalone structure when using createController
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | Medium |
Status | Resolved |
Resolution | Fixed |
Resolution Date | 2013-03-11T15:52:58.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Alloy 1.1.0, 2013 Sprint 04 |
Components | Widgets |
Labels | runtime |
Reporter | Bert Grantges |
Assignee | Unknown |
Created | 2012-11-06T17:54:30.000+0000 |
Updated | 2018-03-07T22:26:03.000+0000 |
Description
Since Widgets are supposed to act as standalone instances, how do I go about creating multiple view/controllers and referencing them appropriately through createController? Example: WIdgetA has two views widget.xml menu.xml WidgetA controller wants to create an instance of menu.xml using createController var m = Alloy.createController("menu", {some object}).getView() Expectation is the above should reference the widgets menu view/controller Actual result – alloy tries to find the controller within the base alloy/controllers folderComments
- Fokke Zandbergen 2012-11-11
Agree 100%, or at least support using WPATH in a widget controller to explicitly reference to other controllers within the widget:
I do see a WPATH implementation in the Alloy-generatedvar row = Alloy.createController(WPATH('row'), arg).getView();
widget.js
:
But using it results in:function WPATH(s) { var index = s.lastIndexOf("/"), path = index === -1 ? "MyWidget/" + s : s.substring(0, index) + "/MyWidget/" + s.substring(index + 1); return path; }
A workaround is to use:alloy/controllers/MyWidget/row
Or is this actually the (undocumented) way to do it? You might think so sincevar row = Alloy.createWidget('MyWidget', 'row', arg).getView();
createWidget
supports a controller name as a second parameter. - Tony Lukasavage 2013-03-11
The was handled in ALOY-530. The Alloy creation functions, like createController(), should be accessed in widget's like this:
This will use the controllers contained within the widget. The same goes for the model and collection creation functions. createWidget() still references the global collection of widgets as it should.widget.createController('viewName', args);