gpt4 book ai didi

javascript - 提交时的搜索栏

转载 作者:行者123 更新时间:2023-12-02 14:38:01 25 4
gpt4 key购买 nike

我正在尝试获取搜索栏的事件,但没有答案...还需要做点什么吗?

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" />

最佳答案

这是因为 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");
});
}

关于javascript - 提交时的搜索栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37271728/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com