Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Problem getting model data on TableView click.

$
0
0

Hi guys, I'm using the 3.1.1GA SDK and have a simple TableView which is hydrated from a model. The table fills out fine, but when I tap on a row, the only real data I get is the index clicked, it doesn't pass the model via the row or rowData properties. Here's the JSON.stringify of the entire event that comes into the click handler.

{
    "x": 136,
    "section": {
        "horizontalWrap": true
    },
    "row": {
        "horizontalWrap": true,
        "className": "accessory_row",
        "id": "acc_row"
    },
    "index": 0,
    "y": 12,
    "rowData": {
        "horizontalWrap": true,
        "className": "accessory_row",
        "id": "acc_row"
    },
    "searchMode": false,
    "detail": false,
    "bubbles": true,
    "type": "click",
    "source": {
        "left": "64dip",
        "id": "prodName",
        "horizontalWrap": true,
        "text": "Zigzag Foot",
        "right": "0dip",
        "height": "50dip"
    },
    "cancelBubble": false
}
Now, the index works fine if I use the model.at(e.index) in most cases, but when I search or filter the data, then the index of the row and the model in the collection don't match up. All of the discussions I've seen about this topic says that the model data should be coming in with row/rowData, but as you can see they don't have any data. Here's the code that makes the table and rows.
<Alloy>
    <Collection src="accessories" />
    <Tab id="browse_tab" title="Accessories" icon="my-accessories.png">
        <Window title="Accessories" id="browse">
            <LeftNavButton>
                <Button id="home_btn" onClick="go_home">Home</Button>
            </LeftNavButton>
            <View id="search_bar">
                <ImageView id="search_icon" />
                <TextField id="search_text" hintText="Search for an accessory" onChange="search_change" />
                <ImageView id="search_cancel" onClick="clear_search" />
            </View>
            <TableView id="browse_acc" dataCollection="accessories" dataFilter="check_filter">
                <Require src="acc_row"></Require>
            </TableView>
        </Window>
    </Tab>
</Alloy>
<Alloy>
    <TableViewRow className="accessory_row">
        <ImageView image="{image}" class="acc_row_img"></ImageView>
        <Label id="prodName" text="{prodName}" />
    </TableViewRow>
</Alloy>
And the click handler:
$.browse_acc.addEventListener('click', function(e) {
    Ti.API.info("model: " + JSON.stringify(e));
    var detailController = Alloy.createController('acc_detail', {
        parentTab : $.browse_tab,
        model : accessories.at(e.index)
    });
    $.browse_tab.open(detailController.getView());
});

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>