Javascript 钛,为屏幕上按下的任何按钮创建动作侦听器

Javascript 钛,为屏幕上按下的任何按钮创建动作侦听器,javascript,function,event-handling,titanium,Javascript,Function,Event Handling,Titanium,所以我在屏幕上有9个按钮,我想要一个动作监听器,这样: -sudo code- frame3.buttion.event-handle({ this.title='clicked'}) -sudo code- 我现在的方式是有9个不同的按钮和事件处理程序,哈哈,不酷。还有一种方法可以创建一个按钮数组,并从该数组中添加和操作按钮,如数组[0]。title=单击?是 var buttons = new Array(); buttons[i] = Ti.UI.createButton({

所以我在屏幕上有9个按钮,我想要一个动作监听器,这样:

-sudo code-

    frame3.buttion.event-handle({ this.title='clicked'})

-sudo code-
我现在的方式是有9个不同的按钮和事件处理程序,哈哈,不酷。还有一种方法可以创建一个按钮数组,并从该数组中添加和操作按钮,如数组[0]。title=单击?

var buttons = new Array();
buttons[i] = Ti.UI.createButton({
    ..........
    //Add this
    my_id:i
});
这可以在以后再次获取

buttons[i].addEventListener('click',function(e)){ 
    var i = e.source.my_id;
    myAction[i] = Ti.Media.createSound({ url: sounds[i] }).play();
    Ti.API.info("clicked button: " + i+ " : "+ myAction[i]);
});


我建议采用完全不同的方法

1) create a view and place all of the buttons in the view.
2) associated one eventListener to the view containing the buttons
3) when the view gets a click event, it will bubble up to the buttons; check the
  event.source.id to determine which button was clicked.

如何将其添加到屏幕。frame3.add(buttons[i])给出错误?var frame3=tianium.UI.createWindow({backgroundColor:'black'})以及如何添加它们?使用for循环?看看您是否添加了var buttons=new Array();第一?我忘了。。。
1) create a view and place all of the buttons in the view.
2) associated one eventListener to the view containing the buttons
3) when the view gets a click event, it will bubble up to the buttons; check the
  event.source.id to determine which button was clicked.