用于搜索的通配符表达式

Wildcard Expression For Searching

本文关键字:表达式 通配符 搜索 用于      更新时间:2023-09-26

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

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'
    });

我不确定如何使用通配符执行此操作,但您可以动态更改最后一行的"filter"属性,使其与搜索值相同:

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进行测试

的。