javascript - Appcelerator Javascript 搜索功能

标签 javascript function appcelerator appcelerator-mobile

我是 Javascript 的新开发人员,需要一些搜索和显示数据的帮助。

我有一个TableView(在index.xml 中),它从index.js 获取数据,并且数据在屏幕上正常显示。我还创建了一个文本字段和搜索按钮,但我需要帮助提取用户输入和搜索存储的数据。

index.xml -

        <Button id="searchButton" onClick="find" class="button">Search</Button>

        <TextField id="SearchtextField" hintText="Search for products: "/>

index.js -

var myproducts = Alloy.Collections.products;

var product = Alloy.createModel('products', {title: 'toy' , desc: 'Toys'});
var product1 = Alloy.createModel('products', {title: 'Yo-yo' , desc: 'Toys'});
var product2 = Alloy.createModel('products', {title: 'Hammer' , desc: 'Hardware'});

myproducts.add(product);
myproducts.add(product1);
myproducts.add(product2);

product.save();
product1.save();
product2.save();

  function find() {



};

我希望用户在搜索文本字段中键入“Hammer”,然后按启动查找功能并显示“Hammer”的搜索按钮。

谢谢

最佳答案

因此,我将提供一种不同的方法,而不是按要求回答您的问题。

在移动设备上,用户期望一致的用户界面,这意味着列表上方有一个“搜索框”或“搜索栏”(在您的情况下为表格 View )。值得庆幸的是,Appcelerator tableview 对象包含一个您无需编写代码的“搜索”内置函数。请查看此处的文档:( http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.TableView-property-search )

此处的 TableViews 指南中还有一个示例 ( http://docs.appcelerator.com/platform/latest/#!/guide/TableViews-section-29004930_TableViews-Searchingwithinatable )

搜索将自动查找标题与搜索字段中输入的值匹配的任何行。因此,只需开始输入“hammer”,它就会将行过滤为仅一行。

关于javascript - Appcelerator Javascript 搜索功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34812408/

相关文章:

c - 在 C 中使用结构体作为输入的语法

android - 如何使用钛模块运行原生 android Activity?

javascript - 有没有办法让 jQuery datepicker 无需几年就能工作?

javascript - jQuery 正则表达式搜索 - 存储所有变量名称

MySQL字符串选择命令

responsive-design - 使用 Appcelerator Titanium 框架进行响应式 UI 设计

javascript - Titanium.App.addEventListener 未触发,从不

javascript - 如果...否则 : If iFrame exists, 将 CSS 应用于页面?

javascript - 为什么在javascript中继承需要原型(prototype)

javascript - 使用 Javascript 从 onClick 更新数据库