2016-12-22 7 views
0

Ich möchte nur fragen, wie kann ich das dynamische Textfeld bei einem Klick aktualisieren? Das Textfeld ist dynamisch und der Wert sollte von beobachtbar sein.Nativescript - Dynamische Textfeldquelle bei Klick aktualisieren

Code hinter

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> 

Antwort