Rechart
Rechart

Reputation: 1

Click an item in a TableViewRow and not on the row

I have a TableView with messages from my members. I added a label to display the number of Like on each post.

How to click on the Label and not on the row?

listeclouds.js

var args = arguments[0] || {};
var dataArray2 = [];

$.tableView.addEventListener("click",function(e) {
  console.log(e.source);
  if (e.source.id == "likeCloud") {
    Ti.API.info("Click like");
  }
});
    var sendit = Ti.Network.createHTTPClient({
        onload: function(){
            var json = JSON.parse(this.responseText);
            //var json = json.todo;
            if(json.length == 0){
                $.tableView.headerTitle = "The database row is empty";
            }
            dataArray2 = [];
            for( var i=0; i<json.length; i++){
                dataArray2.push((Alloy.createController('listecloudsrow', {
                    username: json[i].username,
                    content: json[i].content,
                    filename: json[i].filename,
                    jaimes: json[i].jaimes,
                    coms: json[i].coms,
                    idpost: json[i].id
                }).getView()));
            };
            $.tableView.setData(dataArray2);
        }
    });

    sendit.open('GET', 'http://www.****');
    sendit.send();

listeclouds.xml

<Alloy>
    <Window id="listeclouds" title="Clouds">
        <TableView id="tableView"/>
    </Window>
</Alloy>

listecloudsrow.js

var args = arguments[0] || {};
var clouds = args.content;
$.usernameList.text = args.username;
$.content.text = clouds.replace(/\r\n|\n|\r/gm," ");
$.like.text = args.jaimes;
$.coms.text = args.coms;
if(args.filename)
{
    $.avatar.image = "http://www.********/"+  args.filename;
}else{
    $.avatar.image = "http://www.********/";
}
function montrerCloud(e) {  
    var payload = {
        idpost: args.idpost,
    };
    Alloy.createController('ViewCloud',payload).getView().open();
}

listecloudsrow.xml

<Alloy>
    <TableViewRow class="RowClouds" layout="horizontal" onClick="montrerCloud">
        <View class="GaucheListe" width="10%">
            <ImageView id="avatar"/>
            <Label id="usernameList"/>
        </View>
        <View class="MilieuListe" width="80%">
            <Label id="content"/>
        </View>
        <View class="DroiteListe" width="10%" layout="vertical" id="likeCloud">
            <View layout="horizontal" height="25dp" width="100%">
                <Label id="like" />
                <Label icon="fa-thumbs-up" />
            </View>
            <View layout="horizontal" width="100%">
                <Label id="coms" />
                <Label icon="fa-comments" />
            </View>
            <Widget id="fa" src="com.mattmcfarland.fontawesome"/>
        </View>
        <View height="2dp" width="100%" backgroundColor="#000"></View>
    </TableViewRow>
</Alloy>

Upvotes: 0

Views: 113

Answers (1)

miga
miga

Reputation: 4055

If you added the click listener to the row you'll get the name of the element in the event source:

tableview.addEventListener("click",function(e) {
  console.log(e.source);
  if (e.source.id == "like") { 
        // this is the like label
  }
});

and there you'll see which element receives the click.

Upvotes: 1

Related Questions