Titanium

[ALOY-1082] Allows <Templates> to be children of <Widget>

GitHub Issuen/a
TypeNew Feature
PriorityMedium
StatusResolved
ResolutionWon't Fix
Resolution Date2014-10-27T13:34:16.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsXML
Labelsn/a
ReporterDavide Cassenti
AssigneeTim Poulsen
Created2014-07-14T11:53:14.000+0000
Updated2014-10-27T13:34:16.000+0000

Description

Description

When creating a ListView in a widget, it is not possible to add the templates as children of the widget.

Sample

The ListView is created as a Widget. XML code:
<Alloy>
	<ListView id="list">
		<ListSection>
			<ListItem image:image="someimage.jpg" label:text="this is some text"/>
		</ListSection>
	</ListView>
</Alloy>
The Templates should be added in the index.xml:
<Alloy>
	<Window>
		<Widget src="listtemplate" defaultItemTemplate="template1">
			<Templates>
				<ItemTemplate name="template1" height="100">
					<ImageView bindId="image" id="image"/>
					<Label bindId="label" id="label1"/>
				</ItemTemplate>
			</Templates>
		</Widget>
	</Window>
</Alloy>

Comments

  1. Ingo Muschenetz 2014-07-15 [~dcassenti] Can you please give us an example use case?
  2. Tim Poulsen 2014-07-21

    lib/customlist.js

       var ListView = function(args) {
           this.view = Ti.UI.createListView(args);
       }
       
       ListView.prototype.addMeASectionPlease = function(items) {
           var section = Ti.UI.createListSection();
           section.setItems(items);
           return this.view.appendSection(section);
       }
       ListView.prototype.getView = function() {
           return this.view;
       }
       
       exports.createListView = function(args) {
           return new ListView(args);
       };
       

    index.xml

       <Alloy>
       	<Window>
       		<Label text="Add section" top="20" id="addButton"/>
       		<ListView module="customlist" top="50" id="mylist" defaultTemplate="template">
       			<Templates>
       				<ItemTemplate name="template">
       					<Label bindId="title" id="title"></Label>
       				</ItemTemplate>
       			</Templates>
       		</ListView>
       	</Window>
       </Alloy>
       

    index.js

       $.addButton.addEventListener('click', function() {
       	var items = [
       		{title: {text:'Foo'}, properties: {template:'template', backgroundColor: 'purple'}},
       		{title: {text:'Bar'}, properties: {template:'template'}},
       		{title: {text:'Baz'}, properties: {template:'template'}}
       	];
       	$.mylist.addMeASectionPlease(items);
       })
       
       $.index.open();
       
  3. Tim Poulsen 2014-10-27 Closing, see ALOY-1102 for a solution

JSON Source