我试图在otree上创建一个MPL(多个价格表)(使用PyCharm)。对于我的一个应用程序(WTP),我在html "文件夹"(使用Javascript):
{% if choice.0 > 0 %} If you are paid {{choice.0}} points for this item, would you accept?
{% elif choice.0 == 0 %}
If you are paid {{choice.0}} points for this item, would you accept?
{% elif choice.0 < 0 %}
If you have to pay {{choice.0}} points for this item, would you accept?
{% endif %}
在pages.py:
中定义的不同选择self.participant.vars['choices'] = [
[+30, "choice1", "choice1-yes", "choice1-no"],
[+20, "choice2", "choice2-yes", "choice2-no"],
[+10, "choice3", "choice3-yes", "choice3-no"],
[0, "choice4", "choice4-yes", "choice4-no"],
[-10, "choice5", "choice5-yes", "choice5-no"],
[-20, "choice6", "choice6-yes", "choice6-no"],
[-30, "choice7", "choice7-yes", "choice7-no"],
但是,我希望所有的数字都不带"-"。在参与者的屏幕上签名。如何修改我的Javascript代码,比如-10变成10,-20变成20,-30变成30。
谢谢!
使用Math.abs()
:
Math.abs(-30) // 30
编辑:似乎你的语法是django模板,但你问javascript。如果是这种情况,请使用django mathfilters