1

我有一组具有“选中”和“取消选中”状态的按钮。如何检查数组中的任何按钮是否处于“选定”状态。

所以基本上我想要类似的东西(使用 Framer 咖啡脚本):

for button in buttonArray
    button.onClick ->
       this.stateCycle("selected", "default")

       if any button in buttonArray state.current == "selected"
           activateMainButton()
       else
           deactivateMainButton()

这是我的原型:http ://share.framerjs.com/11abcrlne5op/ (转到种族部分)。

4

1 回答 1

1

我不确定“任何”是指全部还是其中的一些,但有些Array.prototype方法称为someevery

语法是buttonArray.some(button => button.state.current == "selected")

这是在javascript中,咖啡脚本应该有类似的东西

您还可以使用 lodash 库的版本some and every

或者只是在循环中制作一个计数器来计算它们。

于 2017-03-03T08:35:13.963 回答