获取点击的TableRow的ID钛合金? [英] Getting ID of clicked TableRow in Titanium Alloy?

查看:151
本文介绍了获取点击的TableRow的ID钛合金?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的钛和骨干。我与JS框架合作过(最熟悉Knockout.js),但中坚力量,它的工作原理与合金的方式,正在采取一些习惯。

我想要做的东西很简单。我有绑定到一个TableView中的集合。所有我想要做的就是与被点击时的特定行相关的数据。

本应该是微不足道的,但所有的文档似乎假定你知道如何使用合金不已!

型号

  exports.definition = {
    配置:{
        列: {
            主题:TEXT,
            convo_id:整数,
            创建文本,
            修改:TEXT
        },
...

查看

 <&合金GT;
    <窗​​口ID =convosView称号=对话>
        &所述;滚动型的id =convoScrollList>
            &所述; TableView中的id =convoListdataCollection =convos>
                < TableViewRow的onClick =rowClick>
                    < View类=convoRow>
                        < Label类=convoTitle文本={}受/>
                        < Label类=convoDate文本={}创建/>
                        < View类=rowArrow/>
                    < /视图>
                < / TableViewRow>
            < /&的TableView GT;
        < /滚动型>
    < /窗GT;
< /铝合金>

控制器

  VAR对话= Alloy.Collections.convos;
conversations.fetch();功能rowClick(五){
    警报(e.created);
};


解决方案

看看钛fugutive应用程序,我创建的采样口。的基本思想是保存模型的id的表行中,然后在点击,获取模型

  $。table.addEventListener('点击',功能(_E){
    VAR detailController = Alloy.createController('FugitiveDetail',{
        parentTab:$ .fugitiveTab,
        数据:fugitiveCollection.get(_e.rowData.model)
    });
    $ .fugitiveTab.open(detailController.getView());
});

表行构建这样

 <&合金GT;
    <! - 必须使用alloy_id因为我没有在指定架构中的ID - >
    < TableViewRow ID =行数据ID =模型={} alloy_id>
        < View类=vgroup>
            <标签ID =名称文本={}名/>
            <标签ID =地址文本={}地址/>
        < /视图>
    < / TableViewRow>
< /铝合金>

I'm new to Titanium and to Backbone. I've worked with JS frameworks before (most familiar with Knockout.js), but Backbone, and the way it works with Alloy, is taking some getting used to.

I want to do something very simple. I have a collection bound to a TableView. All I want to do is get the data associated with a particular row when it is clicked.

The should be trivial, but all the docs seem to assume you know how to use Alloy already!

Model

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

View

<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>

Controller

var conversations = Alloy.Collections.convos;
conversations.fetch();

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

解决方案

take a look at the sample port of the ti fugutive app I created. The basic idea is to save the id of the model in the table row and then on click, fetch the model.

$.table.addEventListener('click', function(_e) {
    var detailController = Alloy.createController('FugitiveDetail', {
        parentTab : $.fugitiveTab,
        data : fugitiveCollection.get(_e.rowData.model)
    });
    $.fugitiveTab.open(detailController.getView());
});

the table row is constructed like this

<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>

这篇关于获取点击的TableRow的ID钛合金?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆