nativescript-observable-subscribe 是一个能添加订阅功能到 observables 的 NativeScript 模块。
使用:
// viewmodel.js ... var mainViewModel = new HelloWorldModel(); var counterPropName = 'counter'; mainViewModel.subscribe(counterPropName, function(args){ if (this.get(counterPropName) <= 0) { this.set(messagePropName, "Hoorraaay! You unlocked the NativeScript clicker achievement!"); } else { this.set(messagePropName, this.get(counterPropName) + " taps left"); } }, mainViewModel); exports.mainViewModel = mainViewModel;