收藏
回答

不能将类型”string“分配给类型”any[]“?

代码中的actorNames,其他都是any类型,为什么在actorNames = actorNames.join("/");中的第一个actorNames是String类型呢?

给出的报错:不能将类型”string“分配给类型”any[]“

这个怎么解决?

代码:

onLoad:function(options:any{
    //  console.log(options);
    var that = this;
     var type = options.type;
     var id = options.id;
     network.getItemDetail({
       type:type,
       id:id,
       success:function(item:any){
         console.log(item);
         var genres = item.genres;
         genres = genres.join("/");
         var actors = item.actors;
         var actorNames = [];
         if(actors.length > 3){
          actors = actors.slice(0,3);
         }
         for(var index=0;index<actors.length;index++){
           var actor = actors[index];
           actorNames.push(actor.name);
         }
                  // 下面代码中的第一个actorNames怎么就是string类型,第二个actorNames是any类型,怎么解决?
         actorNames = actorNames.join("/");
         var directors = item.directors[0].name;
         var authors = directors+"(导演)/" + actorNames;
         item.genres = genres;
         item.authors = authors;
          that.setData({
            item:item
          })
       }
     })
  },
回答关注问题邀请回答
收藏
登录 后发表内容