【问题标题】:JavaScript: Button in a table viewJavaScript:表格视图中的按钮
【发布时间】:2014-04-07 10:23:15
【问题描述】:

TableViewRow 中的按钮有问题 - 带有 info_button。这个按钮是在 cyklus 的 TableViewRow 的每一行上创建的。当我单击它时,它可以正常工作,根据需要打开警报对话框,但随后它也会打开属于 tableView Row 的代码。 (我剪掉了一段不重要的代码,所以可能会有一些错误,但它工作正常)

var url = "http://hotel.010.sk/skyfit/mysql.php";
var win = Titanium.UI.currentWindow;
var table = Ti.UI.createTableView();
var tableData = [];
var json, harmonogram, vypis, i, row, nameLabel, nickLabel, cvicenie, harmon, backLabel;

var xhr = Ti.Network.createHTTPClient({
onload: function() {
// Ti.API.debug(this.responseText);

json = JSON.parse(this.responseText);


for (i = 0; i < json.harmonogram.length; i++) {
    vypis = json.harmonogram[i];


    row = Ti.UI.createTableViewRow({
        height:80,
        hasChild:true, 
        url:'tab1.js'

    });

var info_button =  Titanium.UI.createButton({
    style:Titanium.UI.iPhone.SystemButton.DISCLOSURE,
    right: '5dp',
    top: 5,
    //buttonid : i 
    id: "image"
});

这是我的info_button,我只需要打开这段代码

info_button.addEventListener('click', function(e) {

          var about = Titanium.UI.createAlertDialog({
            title: 'O cvičení',
            message: vypis.nazov,
            buttonNames: ['OK']
    });
    about.show();

});

//here is CODE for some LABELS, its not important for my problem


row.add(nameLabel);
row.add(nickLabel);
row.add(info_button);
tableData.push(row);


   };


table.setData(tableData);
},
onerror: function(e) {
Ti.API.debug("STATUS: " + this.status);
Ti.API.debug("TEXT:   " + this.responseText);
Ti.API.debug("ERROR:  " + e.error);
alert('There was an error retrieving the remote data. Try again.');
},
timeout:5000
});


xhr.open("GET", url);
xhr.send();

它还会打开这个监听器,如果用户点击它,我只需要打开 info_button。

**table.addEventListener**('click', function(e) {


//here is code for Listener

}); 

win.add(table);

win.open();

非常感谢!

【问题讨论】:

    标签: javascript titanium


    【解决方案1】:

    将按钮的bubbleParent属性设置为false

    例如:-

    Var info_button =  Titanium.UI.createButton({
            bubbleParent: false
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-30
      • 1970-01-01
      • 2010-12-24
      • 1970-01-01
      • 1970-01-01
      • 2018-04-19
      相关资源
      最近更新 更多