帖子
帖子
用户
博客
课程
12下一页
返回列表 发新帖
显示全部楼层
5
帖子
0
勋章
86
Y币

[多端开发] list-view 标签使用update方法

[复制链接]
发表于 2022-6-25 11:04:27
list-view 标签使用update 方法后界面绘制出来了后直接闪退,update 里面是对象数组
发一下能复现你问题的简化版代码,
5
帖子
0
勋章
86
Y币

  1. <template>
  2.         <view class="page">




  3.                 <view class="diss_list_bg">

  4.                         <view class="diss_list_biao"></view>
  5.                         <view class="diss_list_lun_bg">
  6.                                 <view class="diss_list_lun_bg1">
  7.                                         <view class="diss_list_lun_bg2">
  8.                                                 <image class="diss_list_lun_bg2_img" src="../../image/collect/ic_headIcon.png" />
  9.                                                 <image class="diss_list_lun_bg2_img" src="../../image/collect/ic_headIcon.png" />
  10.                                                 <image class="diss_list_lun_bg2_img" src="../../image/collect/ic_headIcon.png" />

  11.                                         </view>

  12.                                         <text class="diss_list_lun_text">354评论</text>
  13.                                 </view>
  14.                                 <image class="diss_list_lun_bg_img1" src="../../image/friend/Vectorclose.png" />
  15.                         </view>


  16.                         <list-view id="listView" class="main" enable-back-to-top onscrolltolower={this.onscrolltolower}>
  17.                                 <cell class="cell" onclick={this.itemClick}>
  18.                                         <view class="cell1">
  19.                                                 <image class="diss_list_lun_bg2_img" src="../../image/collect/ic_headIcon.png" />

  20.                                                 <view class="listView_text">
  21.                                                         <text class="listView_text1"> Philip Schultz </text>
  22.                                                         <text class="listView_text2"> 说明这是一款注定要火的游戏 </text>
  23.                                                         <view class="listView_text_more" @click="itemClickmore">
  24.                                                                 <text> 更多</text>
  25.                                                                 <image class="diss_list_lun_bg2_img" src="../../image/person/Groupxuan.png" />
  26.                                                         </view>
  27.                                                 </view>
  28.                                                 <text class="title">{item.title}</text>

  29.                                         </view>

  30.                                         <view v-for="(itemlun,index) in item.pinlun" :data-index="index" class="cell2">
  31.                                                 <image class="diss_list_lun_bg2_img1" src="../../image/collect/ic_headIcon.png" />
  32.                                                 <view class="listView_text">
  33.                                                         <text class="listView_text1"> Philip Schultz </text>
  34.                                                         <text class="listView_text2"> {itemlun.desc} </text>
  35.                                                 </view>
  36.                                                 <text class="title">{itemlun.diss_title}</text>

  37.                                         </view>


  38.                                         <!-- <view v-if="item.pinlun" :data-index="index" class="cell2">
  39.                                                 <image class="diss_list_lun_bg2_img" src="../../image/collect/ic_headIcon.png" />
  40.                                                 <view class="listView_text">
  41.                                                         <text class="listView_text1"> Philip Schultz </text>
  42.                                                         <text class="listView_text2"> {item.pinlun.desc} </text>
  43.                                                 </view>
  44.                                                 <text class="title">{item.pinlun.diss_title}</text>

  45.                                         </view> -->

  46.                                 </cell>

  47.                         </list-view>



  48.                 </view>
  49.                 <view class="input_diss_bg ">

  50.                         <view class="input_diss_bg1">
  51.                                 <input class="input_diss" placeholder-style="color:#B6B6B6" style="padding-left:5px" type="text"
  52.                                         :placeholder="placeholderPhone"></input>
  53.                                 <image class="input_diss_img" src="../../image/friend/xiao.png" />

  54.                         </view>

  55.                 </view>


  56.         </view>
  57. </template>
  58. <script>

  59. export default {
  60.         name: 'main',

  61.         apiready() { //like created
  62.                 this.initData();
  63.                 // this.initlist();
  64.         },
  65.         data() {
  66.                 return {
  67.                         placeholderPhone: "内容",
  68.                         valuePhone: "",
  69.                         dataList: [{
  70.                                 title: '项目1',
  71.                                 desc: "说明这是一款注定要火的游戏",
  72.                                 diss: true,
  73.                                 pinlun: [
  74.                                         {
  75.                                                 diss_title: '评论1',
  76.                                                 desc: "说明这是一款注定要火的游戏",
  77.                                         },
  78.                                         {
  79.                                                 diss_title: '评论2',
  80.                                                 desc: "说明这是一款注定要火的游戏",
  81.                                         },
  82.                                         {
  83.                                                 diss_title: '评论3',
  84.                                                 desc: "说明这是一款注定要火的游戏",
  85.                                         },


  86.                                 ]
  87.                         },
  88.                         {
  89.                                 title: '项目2',
  90.                                 desc: "说明这是一款注定要火的游戏",
  91.                                 diss: false,
  92.                                 pinlun: []

  93.                         },
  94.                         {
  95.                                 title: '项目3',
  96.                                 desc: "说明这是一款注定要火的游戏",
  97.                                 diss: false,
  98.                                 pinlun: []

  99.                         },
  100.                         {
  101.                                 title: '项目4',
  102.                                 desc: "说明这是一款注定要火的游戏",
  103.                                 diss: false,
  104.                                 pinlun: []
  105.                         },
  106.                         {
  107.                                 title: '项目5',
  108.                                 desc: "说明这是一款注定要火的游戏",
  109.                                 diss: false,
  110.                                 pinlun: []
  111.                         },
  112.                         {
  113.                                 title: '项目6',
  114.                                 desc: "说明这是一款注定要火的游戏",
  115.                                 diss: false,
  116.                                 pinlun: []
  117.                         },
  118.                         {
  119.                                 title: '项目7',
  120.                                 desc: "说明这是一款注定要火的游戏",
  121.                                 diss: false,
  122.                                 pinlun: []
  123.                         }


  124.                         ]
  125.                 };
  126.         },
  127.         methods: {





  128.                 initData() {

  129.                         var dataList = this.dataList;

  130.                         var listView = document.getElementById('listView');

  131.                         // console.log("dataList" + JSON.stringify(dataList));
  132.                         listView.load({
  133.                                 data: dataList
  134.                         });
  135.                 },
  136.                 onscrolltolower() {
  137.                         // this.initData(true);
  138.                 },

  139.                 itemClickmore(e) {

  140.                         var that = this;
  141.                         var listView = document.getElementById('listView');

  142.                         var id = e.currentTarget.index;
  143.                         this.dataList[id].diss = !this.dataList[id].diss;
  144.                         if (!this.dataList[id].diss) {
  145.                                 this.dataList[id].pinlun = [];
  146.                         } else {
  147.                                 var pinlin = [{
  148.                                         diss_title: '评论5',
  149.                                         desc: "说明这是一款注定要火的游戏",
  150.                                 },
  151.                                 {
  152.                                         diss_title: '评论6',
  153.                                         desc: "说明这是一款注定要火的游戏",
  154.                                 },
  155.                                 {
  156.                                         diss_title: '评论7',
  157.                                         desc: "说明这是一款注定要火的游戏",
  158.                                 },

  159.                                 ];
  160.                                 this.dataList[id].pinlun = pinlin;
  161.                         }
  162.                         var datalist1 = this.dataList[id];

  163.                         // {
  164.                         //         diss_title: '评论1',
  165.                         //         desc: "说明这是一款注定要火的游戏",
  166.                         // },
  167.                         // {
  168.                         //         diss_title: '评论1',
  169.                         //         desc: "说明这是一款注定要火的游戏",
  170.                         // },
  171.                         // {
  172.                         //         diss_title: '评论1',
  173.                         //         desc: "说明这是一款注定要火的游戏",
  174.                         // }






  175.                         // console.log("更多" + id + JSON.stringify(this.dataList));

  176.                         try {
  177.                                 // listView.load({
  178.                                 //         data: datalist1
  179.                                 // });

  180.                                 listView.update({
  181.                                         item: datalist1,
  182.                                         index: id
  183.                                 }, function (ret) {
  184.                                         console.log("error------" + ret);

  185.                                 })

  186.                         } catch (error) {
  187.                                 console.log("error" + error);

  188.                         }

  189.                 },

  190.                 itemClick(e) {
  191.                         api.alert({
  192.                                 msg: '当前项索引:' + e.currentTarget.index
  193.                         });
  194.                 }

  195.         }
  196. };
  197. </script>
  198. <style>
  199. .page {
  200.         height: 100%;
  201.         background-color: black;
  202. }
  203. .diss_list_bg {
  204.         background: #313139;
  205.         border-radius: 31.5px;
  206.         position: absolute;
  207.         height: 35rem;
  208.         width: 100%;
  209.         bottom: 0%;
  210.         flex-direction: column;
  211.         /* justify-content: center; */
  212.         align-items: center;
  213. }
  214. .diss_list_biao {
  215.         background: #525255;
  216.         border-radius: 100px;
  217.         height: 3px;
  218.         width: 63px;
  219.         position: absolute;
  220.         top: 1rem;
  221. }
  222. .diss_list_lun_bg {
  223.         position: absolute;
  224.         top: 7%;
  225.         flex-direction: row;
  226.         align-items: center;
  227.         justify-content: space-between;
  228.         width: 20rem;
  229.         height: 34px;
  230.         /* background: #12128a; */
  231.         /* padding-right: 0.5rem; */
  232. }
  233. .diss_list_lun_bg1 {
  234.         width: 18rem;
  235.         height: 34px;
  236.         background: #3c3c3e;
  237.         border-radius: 57px;
  238.         flex-direction: row;
  239.         align-items: center;
  240.         justify-content: space-between;
  241.         background-position: left initial top initial;
  242.         margin-right: 0px;
  243.         margin-left: 0px;
  244.         padding-left: 10px;
  245.         padding-right: 10px;
  246. }
  247. .diss_list_lun_bg_img1 {
  248.         width: 1rem;
  249.         height: 1rem;
  250. }
  251. .diss_list_lun_text {
  252.         color: #838383;
  253.         font-size: 13px;
  254. }
  255. .diss_list_lun_bg2 {
  256.         width: 5rem;
  257.         height: 34px;
  258.         flex-direction: row;
  259.         align-items: center;
  260.         position: relative;
  261.         /* align-items: flex-start; */
  262.         /* justify-content: left; */
  263. }

  264. .listView_text_more {
  265.         flex-direction: row;
  266.         align-items: center;
  267. }
  268. .diss_list_lun_bg2_img {
  269.         width: 1.6rem;
  270.         height: 1.5rem;
  271.         /* margin: 0px -0.4rem; */
  272.         margin-right: -0.4rem;
  273.         /* margin-left: 1rem; */
  274.         /* position: absolute; */
  275. }

  276. .diss_list_lun_bg2_img1 {
  277.         width: 1.7rem;
  278.         height: 1.3rem;
  279.         /* margin: 0px -0.4rem; */
  280.         margin-right: -0.4rem;
  281.         /* margin-left: 1rem; */
  282.         /* position: absolute; */
  283. }
  284. .input_diss_bg {
  285.         width: 100%;
  286.         height: 90px;
  287.         background-color: black;
  288.         position: absolute;
  289.         bottom: 0%;
  290.         flex-direction: row;
  291.         justify-content: center;
  292.         align-items: center;
  293. }
  294. .input_diss_bg1 {
  295.         width: 100%;
  296.         height: 90px;
  297.         /* background-color: rgb(196, 47, 47); */
  298.         position: absolute;
  299.         bottom: 0%;
  300.         flex-direction: row;
  301.         justify-content: center;
  302.         align-items: center;
  303. }
  304. .input_diss {
  305.         background-color: #444444;
  306.         border-radius: 7px;
  307.         box-sizing: border-box;
  308.         position: absolute;
  309.         width: 80%;
  310.         height: 50px;
  311.         z-index: 888;
  312.         /*去边框*/
  313.         border: 0;
  314.         color: cornsilk;
  315. }
  316. .input::-webkit-outer-spin-button,
  317. .input::-webkit-inner-spin-button {
  318.         -webkit-appearance: none !important;
  319.         margin: 0;
  320. }
  321. .input_diss_img {
  322.         z-index: 999;
  323.         width: 30px;
  324.         height: 30px;
  325.         position: absolute;
  326.         right: 11%;
  327. }
  328. .main {
  329.         width: 100%;
  330.         position: absolute;
  331.         height: 24rem;
  332.         top: 5.5rem;
  333. }
  334. .cell {
  335.         /* padding: 8px; */
  336.         /* height: 4rem; */
  337.         border-bottom: 0.5px solid #ddd;
  338.         /* background-color: rgb(160, 19, 19); */
  339.         flex-direction: column;
  340.         /* justify-content: flex-start; */
  341.         align-items: space-around;
  342. }

  343. .cell1 {
  344.         flex-direction: row;
  345.         justify-content: space-around;
  346.         align-items: flex-start;
  347.         padding: 8px;
  348.         /* height: 4rem; */
  349. }

  350. .cell2 {
  351.         flex-direction: row;
  352.         justify-content: space-around;
  353.         align-items: flex-start;
  354.         padding-left: 5rem;
  355. }
  356. .listView_text {
  357.         flex-direction: column;
  358.         align-items: center;
  359.         text-align: left;
  360.         /* height: 4rem; */
  361.         width: 16rem;
  362.         /* background-color: rgb(25, 180, 128); */
  363.         margin-left: 1rem;
  364.         /* height: 60px; */
  365. }
  366. .listView_text1 {
  367.         font-size: 1rem;
  368.         color: #898a8f;
  369. }
  370. .listView_text2 {
  371.         font-size: 1rem;
  372.         color: #b0bcbe;
  373. }
  374. /* .cell:active {
  375.         background-color: #ddd;
  376. } */
  377. .title {
  378.         /* font-weight: bold; */
  379.         /* font-size: 0.8rem; */
  380.         /* color: #000; */
  381.         /* margin-right: 1rem; */
  382.         width: 5rem;
  383.         /* height: 4rem; */
  384.         text-align: center;
  385.         font-size: 1rem;
  386.         color: #898a8f;
  387.         /* background-color: rgb(19, 170, 64); */
  388. }
  389. .subtitle {
  390.         color: #333;
  391. }
  392. .footer {
  393.         justify-content: center;
  394.         align-items: center;
  395. }
  396. </style>
复制代码
技术咨询-特特 · 2022-6-25 11:45发一下能复现你问题的简化版代码,
5
帖子
0
勋章
86
Y币
        <list-view id="listView" class="main" enable-back-to-top onscrolltolower={this.onscrolltolower}>
                                <cell class="cell" onclick={this.itemClick}>
                                        <view class="cell1">
                                                <image class="diss_list_lun_bg2_img" src="../../image/collect/ic_headIcon.png" />

                                                <view class="listView_text">
                                                        <text class="listView_text1"> Philip Schultz </text>
                                                        <text class="listView_text2"> 说明这是一款注定要火的游戏 </text>
                                                        <view class="listView_text_more" @click="itemClickmore">
                                                                <text> 更多</text>
                                                                <image class="diss_list_lun_bg2_img" src="../../image/person/Groupxuan.png" />
                                                        </view>
                                                </view>
                                                <text class="title">{item.title}</text>

                                        </view>

                                        <view v-for="(itemlun,index) in item.pinlun" :data-index="index" class="cell2">
                                                <image class="diss_list_lun_bg2_img1" src="../../image/collect/ic_headIcon.png" />
                                                <view class="listView_text">
                                                        <text class="listView_text1"> Philip Schultz </text>
                                                        <text class="listView_text2"> {itemlun.desc} </text>
                                                </view>
                                                <text class="title">{itemlun.diss_title}</text>

                                        </view>


                                        <!-- <view v-if="item.pinlun" :data-index="index" class="cell2">
                                                <image class="diss_list_lun_bg2_img" src="../../image/collect/ic_headIcon.png" />
                                                <view class="listView_text">
                                                        <text class="listView_text1"> Philip Schultz </text>
                                                        <text class="listView_text2"> {item.pinlun.desc} </text>
                                                </view>
                                                <text class="title">{item.pinlun.diss_title}</text>

                                        </view> -->

                                </cell>

                        </list-view>
技术咨询-特特 · 2022-6-25 11:45发一下能复现你问题的简化版代码,
5
帖子
0
勋章
86
Y币
数据


        dataList: [{
                                title: '项目1',
                                desc: "说明这是一款注定要火的游戏",
                                diss: true,
                                pinlun: [
                                        {
                                                diss_title: '评论1',
                                                desc: "说明这是一款注定要火的游戏",
                                        },
                                        {
                                                diss_title: '评论2',
                                                desc: "说明这是一款注定要火的游戏",
                                        },
                                        {
                                                diss_title: '评论3',
                                                desc: "说明这是一款注定要火的游戏",
                                        },


                                ]
                        },
                        {
                                title: '项目2',
                                desc: "说明这是一款注定要火的游戏",
                                diss: false,
                                pinlun: []

                        },
                        {
                                title: '项目3',
                                desc: "说明这是一款注定要火的游戏",
                                diss: false,
                                pinlun: []

                        },
                        ]
BIP57792 · 2022-6-25 11:56Philip Schultz
                                                         说明这是一款注定要火的游戏
                                                       
5
帖子
0
勋章
86
Y币
点击事件

                itemClickmore(e) {

                        var that = this;
                        var listView = document.getElementById('listView');

                        var id = e.currentTarget.index;
                        this.dataList[id].diss = !this.dataList[id].diss;
                        if (!this.dataList[id].diss) {
                                this.dataList[id].pinlun = [];
                        } else {
                                var pinlin = [{
                                        diss_title: '评论5',
                                        desc: "说明这是一款注定要火的游戏",
                                },
                                {
                                        diss_title: '评论6',
                                        desc: "说明这是一款注定要火的游戏",
                                },
                                {
                                        diss_title: '评论7',
                                        desc: "说明这是一款注定要火的游戏",
                                },

                                ];
                                this.dataList[id].pinlun = pinlin;
                        }
                        var datalist1 = this.dataList[id];

          

                        try {
                                // listView.load({
                                //         data: datalist1
                                // });

                                listView.update({
                                        item: datalist1,
                                        index: id
                                }, function (ret) {
                                        console.log("error------" + ret);

                                })

                        } catch (error) {
                                console.log("error" + error);

                        }

                },
5
帖子
0
勋章
86
Y币
用load 方法就么啥问题,可以绘制出来而且不报错
380
帖子
4
勋章
6
Y币
item: datalist1,

数据需要是数组类型
5
帖子
0
勋章
86
Y币
我这是个数组对象,不能用吗,只能是数组吗
技术咨询-F · 2022-6-26 09:29item: datalist1,

数据需要是数组类型
380
帖子
4
勋章
6
Y币
是的
BIP57792 · 2022-6-27 09:50我这是个数组对象,不能用吗,只能是数组吗
12下一页
您需要登录后才可以回帖 登录

本版积分规则