date里面的某个值再分割成数组显示(已解决)
发布于 6 年前 作者 nluo 14465 次浏览 来自 问答

    RT。我从数据库取出了数组,但现在我想把数组中的某个值再次分割成一个数组分别显示到页面中,请问哪位大神知道怎么做?

我从数据库取出的数据如下:

  1. [{0: "彭德怀", 1: "2018.12.22", 2: "浓情腊八中国风喜庆海报",…}]

    1. 0:{0: "彭德怀", 1: "2018.12.22", 2: "浓情腊八中国风喜庆海报",…}

      1. 0:"彭德怀"

      2. 1:"2018.12.22"

      3. 2:"浓情腊八中国风喜庆海报"

      4. 3:"http://pic2.sc.chinaz.com/files/pic/psd1/201812/psd27892.jpg"

      5. 4:"<a href='http://fjdx.sc.chinaz.net/Files/DownLoad/psd1/201812/psd27892.rar' target="_blank">福建电信下载</a>"

      6. 5:"36291a"

      7. 6:"浓情腊八中国风喜庆海报适用于腊八节海报设计"

      8. 7:"中国风,腊八,腊八节,中华食味,腊月,传统节日,腊八粥,浓情腊八,猪年快乐"

      9. 8:"庆典节日PSD素材"

      10. 9:"24"

      11. 10:"0"

      12. 11:"0"

      13. 12:"0"

      14. 13:"0"

      15. 14:"usertouxiang/pengdiehua.jpg"

      16. biaoqian:"中国风,腊八,腊八节,中华食味,腊月,传统节日,腊八粥,浓情腊八,猪年快乐"

      17. cais:"0"

      18. psd_id:"36291a"

      19. psd_leibie:"庆典节日PSD素材"

      20. psd_miaoshu:"浓情腊八中国风喜庆海报适用于腊八节海报设计"

      21. psd_name:"浓情腊八中国风喜庆海报"

      22. psd_spic:"http://pic2.sc.chinaz.com/files/pic/psd1/201812/psd27892.jpg"

      23. psd_time:"2018.12.22"

      24. psd_user:"彭德怀"

      25. psd_xiazai:"http://fjdx.sc.chinaz.net/Files/DownLoad/psd1/201812/psd27892.rar"

      26. scs:"0"

      27. shares:"0"

      28. user_touxiang:"usertouxiang/pengdiehua.jpg"

      29. views:"24"

      30. zans:"0"

现在我想把此数组中的biaoqian重新按,号分割成一个数组并显示到页面中。

wxml的代码:

<view id=“container”>

   <view class=“bmbox”>

      <ul  class=“bs_show_box” wx:for="{{psdinfo}}" wx:fir-item=“item” wx:key=“psdInfoId”>

        <li class=“list_show_li”>

<view class=“list_show_user border_r”>

            <image class=“list_show_user_touxiang” src=https://www.bbjteam.com/{{item.user_touxiang}}”></image>

            <navigator herf=""><text>{{item.psd_user}}\n{{item.psd_time}}</text></navigator>

            <view class=“clearfix”></view>

          </view>

          <view class=“list_show_share border_r”>

            <text>分享\n<block id=“share_cishu”></block>{{item.shares}}次</text>

          </view>

          <view class=“list_show_liulan border_r”>

            <text>浏览\n<block>{{item.views}}</block></text>

          </view>

          <view class=“list_show_zan border_r”>

            <view class=“zan”>

              <span class=‘bbjicon bbjicon-thumbs-up’ id=“zan_btn”></span>

              <text>赞\n(<block id=“zan_cishu”>{{item.zans}}</block>次)</text>

              <block class=“zan_num”>+1</block>

            </view>

            <view class=“cai”>

<span class=‘bbjicon bbjicon-thumbs-down’ id=“cai”></span>

<text>踩\n(<block id=“cai_cishu”>{{item.cais}}</block>次)</text>

</view>

          </view>

          <view class=“list_show_sc”>

            <span class=‘bbjicon bbjicon-heart’ id=“sc”></span>

<text>收藏\n(<block id=“sc_cishu”>{{item.scs}}</block>次)</text>

          </view>

          <view class=“clearfix”></view>

        </li>

        <li><image src=’{{item.psd_spic}}’ ></image></li>

<li>因为文件太大,请复制一下链接到浏览器下载:</li>

<li> <view class=“tblin_items_btn” bindtap=“copyTBL”>一键复制下载地址</view></li>    

<!-- <li><button type=“primary” bindtap=“DownLoadFile”>复制下载地址</button></li> -->

        <li class=‘list_show_biaoqian’>相关标签:

          {{item.biaoqian}}</li>

        <li><text>注:本网站所有文件解压密码:www.bbjteam.com\n

              本网站部分资源来自网络,如有侵权,请联系站长删除。\n

              联系方式:QQ1343448308,TEL15361501239\n

              如发现链接无法下载,或者展示图片无法显示,也请联系站长。</text>

        </li>

      </ul>

 

    </view>

    <view class=“clearfix”></view>

</view>

js代码:

onLoad: function (options) {

this.setData({

id: options.id

});

var ids = this.data.id;

var that = this;

wx.request({

url: https://www.bbjteam.com/xiaochenxu/bbjteam/index.psdinfo.php,

method: ‘POST’,

data: {

ids: ids

},

header: {

‘content-type’: ‘application/x-www-form-urlencoded’

},

success: function (res) {

that.setData({

psdinfo: res.data,

});

wx.setNavigationBarTitle({

title: that.data.psdinfo[0].psd_name,

})

}

})

}

页面目前效果图:

想要实现效果:

3 回复

### 问题解决

  • js

```

data.biaoqian = data.split(’,’);

```

  • wxml

```

<div v-for=“item in data.biaoqian” :key=“item” class=“item”>{{item}}</div>

```

  • wxss

```

.item {

border: 1px solid red;

padding: 5px;

}

```

### 参考

https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String/split

### 建议

  • 你这个需求是比较简单的js基础语法

  • 首先搞清楚自己要实现的功能

  • 将字符串转换成数组

  • 然后去搜索一下即可

这种基础性的东西,建议在搜索的时候带上 mdn

比如

服务器端标签也打包成一个array就行了。。。

然后在array外加个名称。调用时就用 res.webdata.yourarray

split() 方法用于把一个字符串分割成字符串数组。

http://www.w3school.com.cn/js/jsref_split.asp

回到顶部