找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索本站精品资源

首页 教程频道 小程序开发 查看内容

微信小程序填坑之:多重三元表达式,Page({data:{}}) 页面里 data 的值取出来 ...

作者:模板之家 2018-1-29 10:15 4272人关注

一:页面中多重三元表达式 解析有问题:解决方法: 1 2 3 4 5 6 7 !--{{index}} {{(index==0)?A: (index==1)?B: (index==2)?C:D}}-- blockwx:if={{index==0}}A/block blockwx:elif={{index==1}}B/block blockwx:elif ...

一:页面中多重三元表达式  解析有问题:解决方法:

1
2
3
4
5
6
7
 
<!--{{index}}  {{(index==0)?"A":
                             (index==1)?"B":
                             (index==2)?"C":"D"}}-->
                <block wx:if="{{index==0}}">A</block>
                <block wx:elif="{{index==1}}">B</block>
                <block wx:elif="{{index==2}}">C</block>
                <block wx:else="{{index==3}}">D</block>

二:Page({data:{}}) 页面里 data 的值   可以通过 that.setData 设置   但是 怎么直接取出来 在 js 里面用呢

解决: 在page 之外定义全局变量  和page 内的data中的变量  一一对应  每次 赋初始值或者更改 先给全局变量赋值或者 做更改  然后把 更新后的全局变量赋值给   page 内 data 中 对应的变量  代码如下

 
var app=getApp();
  var globalTestPaperID="",
        globalTestPaperTitle="",
        globalTestPaperNum="",
        globalQuestionList=[],
        globalQuestionIndex=0,
        globalQuestion={},
       // globalAnswerList={},
        globalUserSelectAnswer={},
        golbalUserSelectAnswerContent=""
Page({
    data:{
        testPaperID:"",
        testPaperTitle:"",
        testPaperNum:"",
        questionListSize:0,
        questionIndex:0,
        question:{},
        answerList:{},
        userSelectAnswerContent:""
        
    },
    onReady:function(){},
    onLoad:function(query)
    {
        var that=this;        
      console.log("testPaperTitle-->"+query.testPaperTitle);
      console.log("testPaperID-->"+query.testPaperID);
      console.log("testPaperOrderNum-->"+query.testPaperOrderNum);
            globalTestPaperID=query.testPaperID
             globalTestPaperTitle=query.testPaperTitle
             globalTestPaperNum=query.testPaperOrderNum
         that.setData({
            //  testPaperID:query.testPaperID,
            //  testPaperTitle:query.testPaperTitle,
            //  testPaperNum:query.testPaperOrderNum
            testPaperID:globalTestPaperID,
             testPaperTitle:globalTestPaperTitle,
             testPaperNum:globalTestPaperNum
             }),
三:使用flex属性两边边距自适应解决方案

index.wxml



路过

雷人

握手

鲜花

鸡蛋
原作者: 模板之家 来自: 网络收集

全部回复(0)