【问题标题】:Titanium Mobile Detailed view for row dataTitanium Mobile 行数据的详细视图
【发布时间】:2013-01-31 19:44:26
【问题描述】:

我正在尝试创建我的 json 数据的详细视图。我不确定如何真正接近它。我有事件监听器,但我不确定如何根据所选栏的名称提取数据。这是我的 json 拉取:

var win =Titanium.UI.currentWindow;

var data = [];

var xhr = Titanium.Network.createHTTPClient();

var barList = Titanium.UI.createTableView({
    height:366,
    width: 320,
    top:0,
    left:0
});

win.add(barList);

xhr.onload = function () {
    var json = JSON.parse(this.responseText);
    Ti.API.info(json.length);
    for (var i = 0; i < json.length; i++) {

        var row = Titanium.UI.createTableViewRow({
            hasChild: true,
            className: 'bar-row',
            filter: json[i].bar.name
        });
        var titleLabel = Titanium.UI.createLabel({
            text: json[i].bar.name,
            font: {
                fontSize: 14,
                fontWeight: 'bold'
            },
            left: 70,
            top: 5,
            height: 20,
            width: 210
        });
        row.add(titleLabel);
        var addressLabel = Titanium.UI.createLabel({
            text: json[i].bar.address,
            font: {
                fontSize: 10,
                fontWeight: 'normal'
            },
            left: 70,
            top: 25,
            height: 40,
            width: 200
        });
        row.add(addressLabel);
        var iconImage = Titanium.UI.createImageView({
            text: json[i].bar.logo_file_name,
            width: 50,
            height: 50,
            left: 10,
            top: 10
        });
        row.add(iconImage);
        data.push(row);

        row.addEventListener('click',function(e){
        var detail = Ti.UI.createWindow({
            title: e.rowData.title
        });

    detail.open({modal: true});

})

    }
    barList.data = data;



};


xhr.open('GET', 'http://site.com/db.json');

xhr.send();

JSON 数据: 我正在寻找所选酒吧的名称、描述、mon_special、tues_special 等

http://pastie.org/private/eyp9m5il6hrulbds76a8q

【问题讨论】:

    标签: json titanium titanium-mobile


    【解决方案1】:

    执行此操作的最简单方法是将数据附加到您创建的行:

    var row = Titanium.UI.createTableViewRow({
        hasChild: true,
        className: 'bar-row',
        filter: json[i].bar.name,
        barData : json[i].bar
    });
    

    然后通过事件监听器访问它添加到 TableView 本身(如果你已经创建了行本身,请不要使用事件的 rowData 对象)

    barList.addEventListener('click', function(e) {
        // Get the row clicked, then get our custom attribute
        var passedJSONBarData = e.row.barData;
        // Now pass along through the window, or build the window here
        var detail = Ti.UI.createWindow({
            title: passedJSONBarData.title,
            barData : passedJSONBarData
        });
    
        detail.open({modal: true});
    });
    

    我将事件侦听器添加到表中,以便我们仅在您使用这种方法获得一些性能/内存节省时才创建函数。

    【讨论】:

    • 所以我在进行更改时收到此错误:[ERROR] : Script Error = Attempting to begin a modal transition from &lt;UINavigationController: 0x8e3d120&gt; to &lt;UINavigationController: 0x8e46cf0&gt; while a transition is already in progress. Wait for viewDidAppear/viewDidDisappear to know the current transition has completed at bars.js (line 70).
    • 这是我所做的更改:` var row = Titanium.UI.createTableViewRow({ hasChild: true, className: 'bar-row', filter: json[i].bar.name, barData : json[i].bar.address });`
    • 这不是来自那个变化。我打赌你没有从行中删除事件监听器,所以现在你有两个click 事件触发。从循环内部删除addEventListener。
    • 太好了,这就是问题所在。如何使用数据将行添加到详细视图?如果我要在 var 详细信息窗口中构建窗口?
    • 如果我的回答对您有所帮助,然后接受它,如果您创建一个新问题,我很乐意回答您的其他问题,在 cmets 中很难回答。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多