import { ObservableArray } from "tns-core-modules/data/observable-array" ; import { TokenModel , AutoCompleteEventData } from "nativescript-ui-autocomplete" ; import { Observable } from "tns-core-modules/data/observable" ; import { default as data } from "./cities" ; export class ViewModel extends Observable { constructor ( ) { super ( ) ; this . initDataItems ( ) ; } get dataItems ( ) : ObservableArray < TokenModel > { return this . get ( "_dataItems" ) ; } set dataItems ( value ) { this . set ( "_dataItems" , value ) ; } private initDataItems ( ) { if ( ! this . dataItems ) { this . dataItems = new ObservableArray < CityModel > ( ) ; for ( let i = 0 ; i < data . items . length ; i ++ ) { const d = data . items [ i ] . flag ; const ds = "res://" + d ; this . dataItems . push ( new CityModel ( data . items [ i ] . id , data . items [ i ] . city , data . items [ i ] . country , ds ) ) ; } } } public onTokenAdded ( args ) { console . log ( "Added Token: " + args . token ) ; } public onTokenRemoved ( args ) { console . log ( "Removed Token: " + args . token ) ; } public onTokenSelected ( args ) { console . log ( "Selected Token: " + args . token ) ; } public onTokenDeselected ( args ) { console . log ( "Deselected Token: " + args . token ) ; } } export class CityModel extends TokenModel { public id : number ; public city : string ; public country : string ; constructor ( id , city , country , image ) { super ( city + ", " + country , image ) ; this . id = id ; this . city = city ; this . country = country ; } toString ( ) { return this . id + ": " + this . city + ", " + this . country ; } }