简体   繁体   English

在appcelerator中从tableView获取过滤的数据

[英]Getting filtered data from a tableView in appcelerator

I have a search bar attached to a tableView 我有一个附加在tableView上的搜索栏

searchBar = Ti.UI.createSearchBar({
    value : null,
});

var table = Ti.UI.createTableView({
    filterAttribute: 'filterCriteria',
    search = searchBar
});


var tbl_data = [
   {title:'Row 12', filterCriteria : 'Row 12'},
   {title:'Row 2', filterCriteria : 'Row 2'},
   {title:'Row 3', filterCriteria : 'Row 3'}
];

table.setData(tbl_data);

When I input information into the bar for example "2", the rows are filtered according to the value I input within the search box; 当我在栏中输入信息时,例如“ 2”,行将根据我在搜索框中输入的值进行过滤; in the case of filter "2" the results given would be [{title:'Row 12'}, {title:'Row 2'}] 对于过滤器“ 2”,给出的结果将是[{title:'Row 12'},{title:'Row 2'}]

I can access all data/rows within the table by using 我可以使用来访问表中的所有数据/行

table.data[0].rows;

How am I able to access the filtered rows within the table? 如何访问表中过滤的行?

According to the documentation : http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.TableView-property-filterAttribute the filterAttribute define the property of the TableViewRow to be used. 根据文档: http : filterAttribute定义要使用的TableViewRow的属性。 So, you must add this property on your TableViewRow like this : 因此,您必须像这样在TableViewRow上添加此属性:

var tbl_data = [
  {title:'Row 12', filterCriteria : 'Row 12'},
  {title:'Row 2', filterCriteria : 'Row 2'},
  {title:'Row 3', filterCriteria : 'Row 3'}
];

Then, if you want access to the filtered row, you can add the click event on your TableView : 然后,如果要访问过滤的行,可以在TableView上添加click事件:

table.addEventListener('click', function(e){
  Ti.API.log(' e.row ' + JSON.stringify(e.row)); //the clicked row
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM