xu_binfeng 2019-05-23 15:25 采纳率: 0%
浏览 2873

mock中怎么随机在数组中选取几个(不是一个)返回一个新数组?

例如

//选取1个
"_card_Currency|1": ["人民币", "美元", "日元", "全币种", "港币"]

//重复2次(我要的不是重复)
"_card_Currency|2": ["人民币", "美元", "日元", "全币种", "港币"]

如果想要选取2个怎么做?

  • 写回答

3条回答 默认 最新

  • weixin_40328046 2020-07-10 10:58
    关注
    Mock.Random.extend({
         constellations: [
             { image: "../../images/shopDetail/df1.png", name: "可预约" },
             { image: "../../images/shopDetail/df2.png", name: "提供WIFI" },
             { image: "../../images/shopDetail/df3.png", name: "免费停车" },
             { image: "../../images/shopDetail/df4.png", name: "内设包厢" }
         ], 
         //自定义占位符名字tags
         tags: function (date) {
            //随机选择2个作为返回值
            //return this.pick(this.constellations, 2)
            //随机选择2-4个作为返回值
            return this.pick(this.constellations, 2, 4)
        }, 
     })
    

    数据占位符 DPD
    使用 @tags

    评论

报告相同问题?