0
我只想問一下按鈕單擊後如何更新動態文本框?文本字段是動態的,值應該來自可觀察的。Nativescript - 點擊更新動態文本框源代碼
代碼隱藏
var observableModule = require("data/observable");
var source = new observableModule.Observable();
var HomePage = function() {};
HomePage.prototype = new BasePage();
HomePage.prototype.constructor = HomePage;
HomePage.prototype.contentLoaded = function(args) {
var page = args.object;
source.textSource = "sample";
var layout = page.getViewById("stackID");
var textField = new TextFieldModule.TextField();
var textFieldBindingOptions = {
sourceProperty: "textSource",
targetProperty: "text",
twoWay: false
};
textField.bind(textFieldBindingOptions, source);
layout.addChild(textField);
}
HomePage.prototype.buttonTap = function() {
source.textSource = "new word";
source.update();
}
XML
<stack-layout loaded="contentLoaded" id="stackID">
<Button tap="buttonTap" text="Update" />
</stack-layout>