titanium - Appcelerator钛金JS : Table Alphabetical Index not working

标签 titanium appcelerator titanium-alloy

我正在尝试使用 TableView 索引属性来创建 native 右手字母导航 - 类似于 Apple iOS 联系人应用程序 - 如下图所示:

enter image description here

我创建了一个非常简单的示例,其中包含一组行和行标题,但它不起作用 - 每当我点击索引项时,它都会再次跳转到 TableView 的顶部。

这是我的示例代码:

// Create the first TableViewSection
var section1 = Ti.UI.createTableViewSection({
    headerTitle:'A'
});
// use a loop to add some rows
for (var i=0; i < 20; i++) {
    section1.add(Ti.UI.createTableViewRow({
        title:'Row '+i
    }));
}
// do it all again...
var section2 = Ti.UI.createTableViewSection({
    headerTitle: 'B'
});
for (var i=4; i < 10; i++) {
    section2.add(Ti.UI.createTableViewRow({
        title:'Row '+i
    }));
}
// Now, here's our table, and we're setting the data to hold the sections
var tv = Ti.UI.createTableView({
    data:[section1,section2]
});

// Create a table view index
var index = [
    { title: "A", index: 0 },
    { title: "B", index: 1 }
];

// Set the index on the table view
tv.setIndex(index);

$.index.open();
$.index.add(tv);

最佳答案

这是给你的一个例子,亲爱的

var win = Ti.UI.createWindow();

var table = Ti.UI.createTableView({});

    var contacts = ["Adam", "Andrew", "Boris", "Claus", "Debby", 'Saba', 'Sana', 'Wahhab', 'Zohaib', 'Zzaid', 'Zzxad'];
    var curheader = 'A';
    var sectionArr = [];
    var index = [];
    for (var i = 0, lastL, l, currSection, ilen = contacts.length; i < ilen; i++) {
        l = contacts[i].substr(0, 1);
        if (lastL != l) {
            index.push({
                title : l,
                index : i
            });
            currSection = Ti.UI.createTableViewSection({
                headerTitle : l
            });
            sectionArr.push(currSection);
        }
        currSection.add(Ti.UI.createTableViewRow({
            title : contacts[i],

        }));
        lastL = l;

    }
    table.setData(sectionArr);
    table.index = index;
    win.add(table);
    win.open();

谢谢

关于titanium - Appcelerator钛金JS : Table Alphabetical Index not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22763035/

相关文章:

javascript - 找不到 Ti.cloudpush 模块

android - Appcelerator Android 新的底部导航栏

android - 具有数据收集功能的 Titanium ListViews

android - 应用程序在平板电脑上运行良好,但在 google play 上找不到

javascript - 如何在 Titanium 中并排显示两个 ImageView

javascript - 如何在appcelerator中按日期对一组数据进行排序

ios - 全屏视频将导航栏向上推至状态栏的大小并在退出全屏后保持在那里

javascript - Logged==true 的条件

JavaScript 类方法不起作用

css - 钛合金 - TSS 与 CSS?