Backbone.js 正在获取钛合金中单击的TableRow的ID?

Backbone.js 正在获取钛合金中单击的TableRow的ID?,backbone.js,data-binding,titanium,titanium-alloy,Backbone.js,Data Binding,Titanium,Titanium Alloy,我对钛和脊骨都是新手。我以前使用过JS框架(最熟悉的是Knockout.JS),但是主干以及它使用Alloy的方式需要一些时间来适应 我想做一些非常简单的事情。我有一个绑定到TableView的集合。我只想在单击某一行时获取与该行关联的数据 这应该是微不足道的,但所有的文档似乎都假设你已经知道如何使用Alloy了 型号 exports.definition = { config: { columns: { subject: "text",

我对钛和脊骨都是新手。我以前使用过JS框架(最熟悉的是Knockout.JS),但是主干以及它使用Alloy的方式需要一些时间来适应

我想做一些非常简单的事情。我有一个绑定到TableView的集合。我只想在单击某一行时获取与该行关联的数据

这应该是微不足道的,但所有的文档似乎都假设你已经知道如何使用Alloy了

型号

exports.definition = {
    config: {
        columns: {
            subject: "text",
            convo_id: "integer",
            created: "text",
            modified: "text"
        },
...
查看

<Alloy>
    <Window id="convosView" title="Conversations">
        <ScrollView id="convoScrollList">
            <TableView id="convoList" dataCollection="convos">
                <TableViewRow onClick="rowClick">
                    <View class="convoRow">
                        <Label class="convoTitle" text="{subject}" />
                        <Label class="convoDate" text="{created}" />
                        <View class="rowArrow" />
                    </View>
                </TableViewRow>
            </TableView>
        </ScrollView>
    </Window>
</Alloy>
做这样的事

function rowClick(e) {
    alert(e.rowData);
}; 
<Alloy>
    <!-- have to use alloy_id since I did not specify an id in the schema -->
    <TableViewRow id="row" dataId="" model="{alloy_id}">
        <View class="vgroup">
            <Label id="name" text="{name}"/>
            <Label id="address" text="{address}"/>
        </View>
    </TableViewRow>
</Alloy>
你也可以得到如下索引

function rowClick(e) {
        alert(e.index);
    };

谢谢

看看我创建的ti fugutive应用程序的示例端口。基本思想是将模型的id保存在表行中,然后单击获取模型

$.table.addEventListener('click', function(_e) {
    var detailController = Alloy.createController('FugitiveDetail', {
        parentTab : $.fugitiveTab,
        data : fugitiveCollection.get(_e.rowData.model)
    });
    $.fugitiveTab.open(detailController.getView());
});
表行是这样构造的

function rowClick(e) {
    alert(e.rowData);
}; 
<Alloy>
    <!-- have to use alloy_id since I did not specify an id in the schema -->
    <TableViewRow id="row" dataId="" model="{alloy_id}">
        <View class="vgroup">
            <Label id="name" text="{name}"/>
            <Label id="address" text="{address}"/>
        </View>
    </TableViewRow>
</Alloy>


这部分是正确的。索引肯定可以工作,但是e.rowData只返回XML声明中存在的参数。我想返回行绑定到的实际模型数据。啊,因此您仍然需要在XML中连接要检索的属性(在本例中,通过
model=“{alloy_id}”
)。我对数据绑定的假设是,这种事情是不必要的。视图中模型的表示本质上与数据对象相关联。它出现在Alloy中,但事实并非如此。您仍然需要绑定字段,但理论上框架可以确定idAttribute并在视图中设置它