javascript - How to convert string JSON data in the applet to Number type
过去多啦不再A梦
过去多啦不再A梦 2017-05-18 10:51:21
0
2
649
/** index.js*/ var app = getApp() Page({ data: { /** * 页面配置 */ winWidth: 0, winHeight: 0, // tab切换 currentTab: 0, option1:[ {value:"1",contant:"A:xxxx"}, {value:"2",contant:"B:xxxx"}, {value:"3",contant:"C:xxxx"}, {value:"4",contant:"D:xxxx"} ], option2: [ { value: "1", contant: "A:xxxx" }, { value: "2", contant: "B:xxxx" }, { value: "3", contant: "C:xxxx" }, { value: "4", contant: "D:xxxx" } ], option3: [ { value: "1", contant: "A:xxxx" }, { value: "2", contant: "B:xxxx" }, { value: "3", contant: "C:xxxx" }, { value: "4", contant: "D:xxxx" } ], option1Value:0, option2Value:0, option3Value:0, }, onLoad: function() { swiperChange: function(e){ var that = this; if(that.data.currentTab==0){ that.setData({ option1Value : e.detail.value, currentTab: 1 }); }else if(that.data.currentTab==1){ that.setData({ option2Value : e.detail.value, currentTab: 2 }); }else if(that.data.currentTab==2){ that.setData({ option3Value : e.detail.value, currentTab: 3 }) } } })    第一题 第二题 第三题                       {{score}} 

The above is my code. I want to realize that there are three questions on the page, each with four options with different scores. The results will pop up directly after the user selects. However, the JSON data that stores the options selected by the user is a string. How to convert it? For numeric type?

过去多啦不再A梦
过去多啦不再A梦

reply all (2)
淡淡烟草味
e.detail.value - 0

    仅有的幸福

    When you save it, it is a number, and when it is parsed, it is a number...
    Now you are saving a string..
    If you want to convert it, just
    +e.detail.value will do

      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!