• 百度小程序坑坑坑


    吐槽:被小程序坑死啊

    问题:在循环中,根据条件加载不同的template模板出现问题。

       <block s-for="news, index in item.news_data">
            <!--begin template is 中第一次比较,满足就会出现问题 -->
            <block s-if="item.type==1">
                <template is="newsText" data="{{{...item}}}"></template>
            </block>
            <block s-elif="item.type==2">
                    <block s-if="item.datu==1">
                        <template is="newsBigImg" data="{{{...item}}}"></template>
                    </block>
                    <block s-else>
                        <template is="newsTags" data="{{{...item}}}"></template>
                    </block>
            </block>
            <block s-else>
                <template is="newsImgs" data="{{{...item}}}"></template>
            </block>
            <!--end template is 中第一次比较,满足就会出现问题-->
            
            
            <!-- 原始写法 -->
            <!-- <template is="{{news.type==1?'newsText':(news.type==2?(news.datu==1?'newsBigImg':'newsTags'):'newsImgs')}}" data="{{{...news}}}"></template> -->
            
          </block>

    问题刚出现的时候,是一个明明只id为xxxx的只有一条,可是页面却出现了多条,以为是s-for的问题就一直在这纠结,然后就百度,就那么几条:1:s-for和s-if 不能用到一个元素(不是这个问题),2:后端加载数据是对象而不是数组需要替换,3:什么不能识别常量问题(什么鬼哦)。然后就查看数据有啥不同,发现该条数据是文本显示而不是带图的文本显示,查看代码没问题;

    然后就

    怀疑1:是不是{{}}里面不能使用三元运算,发现不是;

    怀疑2:是不是s-for 里面不支持 三元运算,也不是;

    怀疑3: template is 中不支持 三元运算 ,不完全是。

    template中的is 支持三元运算,但是就第一次比较的时候,如果满足,就会出现问题。(找了很久,巨坑啊)

    附加问题:

    swan.getSystemInfo({
          success: function (res) {
            that.setData({
              pageHeight:windowHeight
            });
        
          }

    这里获取的windowHeight在真机上面也是不准确的,

    解决:在需要获取可使用窗口高度的对应js文件中,onReady 中调用wx.getSystemInfo.

    windowHeight=screenHeight-导航高度

  • 相关阅读:
    适配器
    策略
    oom的各种情况
    sql 优化//TODO
    聚簇索引和非聚簇索引
    Shard内部原理
    es集群健康状态
    转载 R语言颜色基础设置
    三维数据的展示
    python 文件保存 出错
  • 原文地址:https://www.cnblogs.com/-lin/p/11015798.html
Copyright © 2020-2023  润新知