收藏
回答

接受到的类型不兼容的值:但得到的是非数组,而使用了空数组?

确报了一大串警告,看着这警告很烦,这个问题怎么解决?图片:

代码:

components代码
// components/indexmodule/indexmodule.ts
Component({
  properties: {
    items:{
      type:Array,
      value:[]
    },
  },
<!--components/indexmodule/indexmodule.wxml-->
<scroll-view class="module-scroll-view" scroll-x="{{true}}">
  <itemview wx:for="{{items}}" wx:key="title"></itemview>
</scroll-view>
pages页面代码
<!--index.wxml-->
<indexmodule items="{{movies}}"></indexmodule>
// index.ts
 onLoad() {
  var that = this;
  network.getMovieList({
    success:function(movies:any){
      that.setData({
        movies:movies
      })
    }
  })
}
//  /utils/urls。ts
getMovieListfunction (params: any{
      params.type = "movie";
      this.getItemList(params);
   },
getItemListfunction (params: any{
      var url = "";
      if (params.type === 'movie') {
         url = globalUrls.movieList;
      } else if (params.type === 'tv') {
         url = globalUrls.tvList;
      } else {
         url = globalUrls.showList;
      }
      var count = params.count ? params.count:7;
      wx.request({
         url: url,
         data: {
            count: count,
         },
         successfunction (res: any{
            //  console.log(res);
            var items = res.data.subject_collection_items;
            var itemsCount = items.length;
            var left = itemsCount%3;
            if(left === 2){
               items.push(null)
            }
            if (params && params.success) {
               params.success(items);
            }
         }
      })
   }
回答关注问题邀请回答
收藏

2 个回答

  • Jianbo
    Jianbo
    2023-09-30

    需要加一个items非空的判断, 比如 items.length==0

    2023-09-30
    有用
    回复 1
    • 蓝天☁
      蓝天☁
      2023-09-30
      在哪里加
      2023-09-30
      回复
  • Jerry
    Jerry
    发表于小程序端
    2023-09-29

    你看你的items是个数组吗?

    2023-09-29
    有用
    回复
登录 后发表内容