В моето приложение Ti.App.addEventListener изпълни няколко пъти дори извиквания на fireEvent веднъж.
Не можах да премахна fireEvent. Как да премахнете създаденото fireEvent.
Ето моите примерни файлове:
selectUser.xml
Alloy>
<NavigationWindow id="selectUserNav" platform="ios">
<Window id="selectUserWin">
<Label id="selectUserLabel"/>
<Label id="userName"/>
</Window>
</NavigationWindow>
</Alloy>
selectUser.js
var selectedUser = '';
function displaySelectedUser(){
$.selectUserLabel.setText('Select the user');
$.userName.setText(selectedUser);
}
displaySelectedUser();
$.selectUserWin.addEventListener('open', function() {
var titleLabel = Ti.UI.createLabel({
text : 'Select User',
});
$.selectUserWin.setTitleControl(titleLabel);
var leftView = Ti.UI.createView({
});
var leftButton = Titanium.UI.createButton({
backgroundImage : '/left_arrow.png'
});
leftView.add(leftButton);
$.selectUserWin.setLeftNavButton(leftView);
var rightView = Ti.UI.createView({
});
var rightButton = Titanium.UI.createButton({
backgroundImage : '/right_arrow.png'
});
rightView.add(rightButton);
$.selectUserWin.setRightNavButton(rightView);
leftButton.addEventListener('click', function(e) {
$.selectUserNav.close();
});
rightButton.addEventListener('click', function(e) {
Alloy.createController('usersList').getView().open();
});
});
Ti.App.addEventListener('username', function(data) {
Ti.API.info('### selectedUser: '+ data.selectedUserName);
selectedUser = data.selectedUserName;
displaySelectedUser();
});
usersList.xml
Alloy>
<NavigationWindow id="usersListNav" platform="ios">
<Window id="usersListWin">
<TableView id="usersDispTable"></TableView>
</Window>
</NavigationWindow>
</Alloy>
usersList.js
var usersTableData = [];
function userList(){
for ( i = 0; i < 5; i++) {
var titleLabel1 = Titanium.UI.createLabel({
text : 'srinivas',
});
var userListRow = Ti.UI.createTableViewRow({
userName : 'srinivas',
height : '40',
});
userListRow.add(titleLabel1);
usersTableData.push(userListRow);
userListRow.addEventListener('click', function(e) {
var selectedArgs = {
selectedUserName : e.rowData.userName
};
Ti.App.fireEvent('username', selectedArgs);
$.usersListNav.close();
});
}
$.usersDispTable.setData(usersTableData);
}
userList();
$.usersListWin.addEventListener('open', function() {
var titleLabel = Ti.UI.createLabel({
text : 'Users List',
});
$.usersListWin.setTitleControl(titleLabel);
var leftView = Ti.UI.createView({
});
var leftButton = Titanium.UI.createButton({
backgroundImage : '/left_arrow.png'
});
leftView.add(leftButton);
$.usersListWin.setLeftNavButton(leftView);
leftButton.addEventListener('click', function(e) {
$.usersListNav.close();
});
});