Android Nativescript-单击更新动态文本字段源

Android Nativescript-单击更新动态文本字段源,android,nativescript,Android,Nativescript,我只是想问一下,如何在单击按钮时更新动态文本字段?textfield是动态的,值应该来自observable 代码隐藏 var observableModule = require("data/observable"); var source = new observableModule.Observable(); var HomePage = function() {}; HomePage.prototype = new BasePage(); HomePage.prototype.cons

我只是想问一下,如何在单击按钮时更新动态文本字段?textfield是动态的,值应该来自observable

代码隐藏

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>

我可以在单击时找到如何更新源代码的方法

HomePage.prototype.onTap = function() {
  source.set("textSource", "new word");
}

资料来源:

我可以在点击时找到如何更新资料来源的信息

HomePage.prototype.onTap = function() {
  source.set("textSource", "new word");
}
资料来源: