0

我有一个按钮,我想在搜索结果的末尾显示它。为此,我在表格行中添加了“过滤器”属性。无论在搜索栏中输入什么内容,我都需要一种方法来调用该行(例如过滤器匹配)。我想我需要某种形式的通配符。做了一些研究,我还没有找到任何简单地显示通配符的东西。我的大部分结果似乎都使用了正则表达式。那么,有可能做到这一点吗?

search : Ti.UI.createSearchBar({
        barColor : '#666',
        height : '45dp',
        top : 0,
        showCancel : false
    }),
    filterAttribute : 'filter',
//Above is from the Table code, below is the row's code.
var buttonRow = Ti.UI.createTableViewRow({
        backgroundImage : $$.components.RowBG,
        selectionStyle : 'none',
        height : '60dp',
                filter : 'I NEED THIS FILTER TO RETURN NO MATTER WHAT IS INPUTTED IN SEARCH'
    });
4

1 回答 1

0

我不确定您将如何使用通配符来执行此操作,但您可以动态地将最后一行的“过滤器”属性更改为与搜索值相同:

var data = ['oranges', 'grapes', 'lemons', 'kiwi', 'apples', 'limes'];

var rows = [];

for (var i = 0; i < data.length; i++) {
    var row = Ti.UI.createTableViewRow({
        title : data[i],
        filter : data[i]
    });
    rows.push(row);
}

var magicRow = Ti.UI.createTableViewRow({
    title : 'I am always here',
    filter : 'set by code'
});
rows.push(magicRow);

var search = Titanium.UI.createSearchBar({
    barColor : '#000',
    showCancel : true,
    height : 43,
    top : 0,
});

search.addEventListener('change', function(e) {
    // Set the last row filter to the current search value
    magicRow.filter = e.source.value;//
    //table.updateRow(rows.length - 1, magicRow,{animationStyle:Ti.UI.iPhone.RowAnimationStyle.NONE}); <- Should work but flickers
    // setting the data seems to work better
    table.data = rows;
});

var table = Ti.UI.createTableView({
    data : rows,
    filterAttribute : 'filter',
    search : search
});

这是在 iOS 上使用 Titanium SDK 2.0.1.GA2 测试的

于 2012-06-29T22:13:06.637 回答