问题
I am new to Nativescript. Yesterday I asked how to create a slider and read those values. This question was answered however now I want to log those values once the value of the slider has been updated.
I made a sample project that prints the value once I press a button. Now I want to print the value each time the value of the slider changes. I looked at the slider documentation and the propertyChange event documentation but can't get this to work.
Here is the link to the playground I am trying this in: Playground
Can anybody tell me how I'd properly bind my slider to the observable and how I'd capture the event that fires once the value updates?
Thanks in advance!
回答1:
You could attach to the valueChange
listener via code-behind.
exports.onSliderLoaded = function (args) {
const slider = args.object;
slider.on("valueChange", (args) => {
console.log(args.value);
})
}
Where onSliderLoaded
is used via the loaded
event for your slider
<Slider value="{{ slider }}" loaded="onSliderLoaded" />
Full Playground demo demonstrating the above can be found here
来源:https://stackoverflow.com/questions/49800467/nativescript-log-slider-value-on-update