我想知道搜索栏里发生的事情,但没有人回答.有必要做更多的事情吗?
ts:
import {CompaniesViewModel} from "../../shared/models/companyModel";
import {Page} from "ui/page";
import {SearchBar} from "ui/search-bar";
export function pageLoaded(args) {
console.log('pageLoaded');
var page = <Page>args.object;
page.bindingContext = new CompaniesViewModel();
var searchBar = new SearchBar();
searchBar.on(SearchBar.submitEvent, function (args) {
console.log("Search for " + (<SearchBar>args.object).text);
});
searchBar.on(SearchBar.clearEvent, function (args) {
console.log("Clear");
});
}xms:
<SearchBar row="1" text="{{ search }}" hint="NIF ou Nome da empresa" id="search" />发布于 2016-05-17 10:44:18
这是因为searchBar变量是用一个新的SearchBar初始化的,并且与您在XML中定义的搜索栏无关。因此,您的TS应该更改为:
import {CompaniesViewModel} from "../../shared/models/companyModel";
import {Page} from "ui/page";
import {SearchBar} from "ui/search-bar";
export function pageLoaded(args) {
console.log('pageLoaded');
var page = <Page>args.object;
page.bindingContext = new CompaniesViewModel();
var searchBar = page.getViewById<SearchBar>("search");
searchBar.on(SearchBar.submitEvent, function (args) {
console.log("Search for " + (<SearchBar>args.object).text);
});
searchBar.on(SearchBar.clearEvent, function (args) {
console.log("Clear");
});
}https://stackoverflow.com/questions/37271728
复制相似问题