0
在我的應用中,Ti.App.addEventListener多次執行多次fireEvent調用一次。
我無法刪除fireEvent。 如何刪除創建的fireEvent。無法限制Ti.App.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();
});
});
其實我想通過從usersList.js控制器所選擇的用戶名之前打開屏幕即selectUser.js 當我打開兩個控制器多次調用selectUser.js Ti.App.addEventListener多次調用。 – Chanakya
fireEvent在usersList.js: userListRow.addEventListener( '點擊',函數(E){ VAR selectedArgs = { selectedUserName:e.rowData.userName }; Ti.App.fireEvent( '用戶名',selectedArgs ); $ .usersListNav.close(); }); – Chanakya
EventLister在selectUser.js:(下面聽者多次調用) Ti.App.addEventListener( '用戶名',功能(數據){ Ti.API.info( '### selectedUser:' + data.selectedUserName ); selectedUser = data.selectedUserName; displaySelectedUser(); }); – Chanakya