Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-19327] ListView - template event handler not working if using "var" declaratoin

GitHub Issuen/a
TypeBug
PriorityNone
StatusOpen
ResolutionUnresolved
Affected Version/sRelease 4.1.1
Fix Version/sn/a
ComponentsAndroid, iOS
Labelsn/a
ReporterShawn Lan
AssigneeUnknown
Created2015-07-31T19:10:34.000+0000
Updated2018-02-28T19:55:14.000+0000

Description

Create a default Alloy project with the following: index.xml
<Alloy>
	<Window>
		<ListView defaultItemTemplate="template" onItemclick="list1Click" backgroundColor="white">
			<Templates>
	            <ItemTemplate name="template">
	            	<View onLongpress="handler">
	                    <Label bindId="title" />
	                </View>
	            </ItemTemplate>
	        </Templates>
			<ListSection>
				<ListItem title:text="TEST ITEM 1" />
				<ListItem title:text="TEST ITEM 2" />
			</ListSection>
		</ListView>
	</Window>
</Alloy>
index.js
var handler = function() {
	Ti.API.info("longpressed");
};

var list1Click = function(){
	Ti.API.info("item clicked");
};
$.index.open();
On iOS, the function "handler" is simply not working. On Android, it'll throw exception saying event handler undefined. However, itemclick event works fine. If we declare function "handler" like the following, then it works fine on both iOS and Android.
function handler() {
	Ti.API.info("longpressed");
}

var list1Click = function(){
	Ti.API.info("item clicked");
};
$.index.open();
So event handler for template element can't be declared using "var." This inconsistency could cause confusion to developer.

Comments

No comments

JSON Source