Nativescript get value of textfield

I had to get the value of a textfield using JavaScript in NativeScript; I tried a bunch of things and ended up just using a global variable to bind it.

XML:

<TextField id=”searchBox” text=”{{searchContents}}” />

And in the <Page> tag, add in:

loaded=”loaded”

JavaScript:

var model = {searchContents: “”};

exports.loaded = function(e){
var page = e.object;
page.bindingContext = model;
}

 

Then I could get it with model.searchContents;

No
Comments

Comments are now closed.