Nativescript log slider value on update

心不动则不痛 提交于 2019-12-23 05:24:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!