Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rater评分组件如何获取当前的评分值呢? #4

Closed
acid122 opened this issue Apr 6, 2017 · 3 comments
Closed

rater评分组件如何获取当前的评分值呢? #4

acid122 opened this issue Apr 6, 2017 · 3 comments

Comments

@acid122
Copy link

acid122 commented Apr 6, 2017

rater组件的rater.js文件中:
/**

  • 点击触发事件
    */
    bindtap(e) {
    const i = e.currentTarget.dataset.index
    const rater = this.page.data.$wux.rater[id]
    const value = rater.value
    const disabled = rater.disabled

      			if (disabled) return !1
    
      			if (value === i + 1) {
      				this.page.setData({
      					[`$wux.rater.${id}.value`]: i
      				})
      			} else {
      				this.page.setData({
      					[`$wux.rater.${id}.value`]: i + 1
      				})
      			}
    
      			that.updateStyle(id, this.page)
      			that.updateValue(id, this.page)
    
      			typeof options.callback === `function` && options.callback(e)
      		}
    

上面代码中,评分回调函数options.callback(e)的参数e好像并没有带上用户选中评分的value,请问是我理解有误还是有其他方式来获得当前用户选中的评分值,谢谢:)

@skyvow
Copy link
Member

skyvow commented Apr 6, 2017

this.data.$wux.rater[id].value

@acid122
Copy link
Author

acid122 commented Apr 8, 2017

谢谢朋友,你的这个组件库做的很不错,我正在考虑学习使用,直接用你提供的this.data.$wux.rater[id].value会报类似"cannot read property $wux of undefined "的错误,下面的代码我是参考小程序官网的写法,在外部通过that传值到callback函数进行后续对data属性的引用,但是不知道能否用es6的箭头函数进行改进呢?
onLoad() {
var that=this;
$wuxRater.init('star', {
value: 5,
callback:function (e){
console.log(that.data.$wux.rater['star'].value);
}
});
}

@skyvow
Copy link
Member

skyvow commented Apr 9, 2017

非常感谢您的支持,后续我已经做出了修改,可查看2017-04-09 更新日志

@skyvow skyvow closed this as completed Apr 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants