【问题标题】:Wildcard Expression For Searching用于搜索的通配符表达式
【发布时间】:2012-06-28 19:25:13
【问题描述】:

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

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

【问题讨论】:

    标签: javascript search titanium appcelerator


    【解决方案1】:

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

    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 测试的

    【讨论】:

      猜你喜欢
      • 2011-09-14
      • 2019-07-29
      • 2015-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-15
      • 1970-01-01
      相关资源
      最近更新 更多