Get bindId from added data to an TableView inside

2019-07-14 17:54发布

问题:

I've a ListView rotated -90 degrees, with it's ListItem's rotated 90 degrees built in Alloy Titanium.

Each ListItem has a header Label and a content TableView, and the TableView data is dynamic.

This is my index.xml:

<Alloy>
    <Window>
        <ListView id="view" defaultItemTemplate="item">
            <Templates>
                <ItemTemplate id="item" name="item">
                    <View id="view" bindId="view">
                        <View class="header">
                            <Label class="title" bindId="title"/>
                            <Label class="subtitle" bindId="subtitle"/>
                            <Label class="desc" bindId="desc"/>
                            <View class="border"/>
                        </View>
                        <TableView class="content" bindId="content"/>
                    </View>
                </ItemTemplate>
            </Templates>
            <ListSection/>
        </ListView>
    </Window>
</Alloy>

I'm setting each TableView data like this:

var items = [];

items.push({
    properties: {
        backgroundColor: "#fff",
        width: config.height,
        height: config.row
    },
    title: {
        text: "title"
    },
    content: {
        data: rows //TableViewRow's array
    }
});

$.view.sections[0].setItems(items);

The problem is when I want to get the id of the clicked row.

This is my itemclick event (item index and tableview data):

$.view.addEventListener("itemclick", function(e) {

    console.log("clicked on item: " + e.itemIndex);

    var item = $.view.sections[0].getItemAt(e.itemIndex);

    _.map(item.content.data || [], function(row) {

        console.log(row);

        row = null;
    });
});

There is any way to get the index of the clicked row?

I've tried to add that same event to all of this object properties, but still no luck:

item.click
item.onclick
item.properties.click
item.properties.onclick
item.content.click
item.content.onclick
item.content.properties.click
item.content.properties.onclick
item.events.click
item.events.onclick
item.properties.events.click
item.properties.events.onclick
item.content.events.click
item.content.events.onclick
item.content.properties.events.click
item.content.properties.events.onclick

I've also tried to add the event listener to all of the rows

回答1:

You can set the

itemId

for this