0
我无法从绑定的文本框中获取值。我使用了选项卡模板。在Microsoft Android模拟器上。有什么我需要添加到主标签页视图模型可能吗?Nativescript标签页文本框
查看
<GridLayout class="page-content">
<StackLayout orientation="vertical">
<Label class="page-icon fa" text=""></Label>
<TextField id="txtSearch" text="{{ search }}" hint="Search" keyboardType="email" autocorrect="false" autocapitalizationType="none" />
<Button text="Sign in" tap="searchClick" />
</StackLayout>
</GridLayout>
var SearchViewModel = require("./search-view-model");
var svm = new SearchViewModel();
function onLoaded(args) {
var component = args.object;
component.bindingContext = new SearchViewModel();
}
exports.searchClick = function() {
svm.searches()
.catch(function(error) {
console.log(error);
dialogsModule.alert({
message: "Unfortunately we could not find your account.",
okButtonText: "OK"
});
return Promise.reject();
})
.then(function() {
//frameModule.topmost().navigate("views/list/list");
});
};
exports.onLoaded = onLoaded;
模式 出于某种原因viewModel.get( “搜索”)没有返回。按钮点火正常。
const observableModule = require("data/observable");
var fetchModule = require("fetch");
//Info is the returning object
function SearchViewModel(info) {
info = info || {};
var viewModel = new observableModule.fromObject({
search: info.search || ""
});
viewModel.searches = function() {
var test = viewModel.get("search");
return fetchModule.fetch(config.apiUrl + viewModel.get("search"), {
method: "GET",
headers: {
"Content-Type": "application/json"
}
})
.then(handleErrors)
.then(function(response) {
return response.json();
})
.then(function(data) {
config.token = data.Result.access_token;
});
};
return viewModel;
}
使用this.get没有区别(“搜索”) 对不起,我没有粘贴使用svm的click事件。我会添加它。有没有其他的方式来使用它的地方? – Jason
只要做到这一点。在你的代码后面,编写'component.bindingContext = svm;'而不是当前行 –
其实也试过了。看起来我的onLoaded函数从来没有被击中,或者至少它没有达到我的中断点。所以绑定永远不会发生。 – Jason