vue中json处理方法

0 0 javascript html css vue.js u524du7aef
汉有游女,不可求思。
2019-01-05 10:48:14 提问

关注 0关注

收藏 0收藏, 32浏览



{{item.lesson_name}}

请先 登录 后评论

4个回答

  • wolfing_85声望 2018-09-25 09:30

    首先,不需要显示的数据你不调用不就行了么? this.json = this.json.filter(lesson => lesson.lesson_name !== '标准xxx');
    请先 登录 后评论
  • 写bug小能手103声望 2018-09-25 09:30

    computed:{ needJson(){ let a=this.json.pop() return this.json.filter(v=>{ return v!=a }) } }然后 v-for="item in needJson"
    请先 登录 后评论
  • 半盛&梦夏149声望 2018-09-25 09:30

    我觉得你这个把它整麻烦了,完全没必要非要去操作数据,你不想要那条数据,就不让那一条显示就好,而且你可以把你现在created周期里的函数放到mouted里面试一下,看是不是你那个逻辑写错了。 我的解决办法是(不用created里面删除数据,不显示那一条就行): <div id="myapp"> //当根据数据循环创建时,若课程名称不等于不想显示的那一条数据才使其创建,否则不创建 <div v-for="item in json" v-if="item.lesson_name != '标准陪练-5节'"> <p>{{item.lesson_name}}</p> </div> </div>
    请先 登录 后评论
  • wolfing_85声望 2018-09-25 09:30

    大兄弟,用你的方法我也试了下没问题下面是代码 <div id="app"> <ul> <li v-for="needJson in needJsons">{{needJson}}</li> </ul> </div> <script> new Vue({ el: '#app', data() { return { jsons: [ { "type_name": "正课", "lesson_name": "标准陪练课(中级)-90节", "course_name": "标准陪练", "lesson_no": "BZ-c2-3", "lesson_num": 90, "lesson_id": 37, "xufei_buy_num": 1, "level_name": "中级", "money": 11380, "shengyu_lesson_num": 100, "free_lesson_num": 12, "mode_name": "陪练", "tuifei_num": 0, "modify_date": "2017-10-16 13:32:41", "lesson_min": 50, "shouci_buy_num": 1 }, { "type_name": "正课", "lesson_name": "标准陪练课(中级)-120节", "course_name": "标准陪练", "lesson_no": "BZ-c2-4", "lesson_num": 120, "lesson_id": 38, "xufei_buy_num": 0, "level_name": "中级", "money": 14180, "shengyu_lesson_num": 0, "free_lesson_num": 0, "mode_name": "陪练", "tuifei_num": 0, "modify_date": "2017-10-16 13:33:38", "lesson_min": 50, "shouci_buy_num": 0 }, { "type_name": "正课", "lesson_name": "标准陪练课(中级)-200节", "course_name": "标准陪练", "lesson_no": "BZ-c2-5", "lesson_num": 200, "lesson_id": 39, "xufei_buy_num": 0, "level_name": "中级", "money": 22880, "shengyu_lesson_num": 217, "free_lesson_num": 17, "mode_name": "陪练", "tuifei_num": 0, "modify_date": "2017-10-16 13:35:01", "lesson_min": 50, "shouci_buy_num": 1 }, { "type_name": "正课", "lesson_name": "标准陪练课(高级)-30节", "course_name": "标准陪练", "lesson_no": "BZ-c3-1", "lesson_num": 30, "lesson_id": 40, "xufei_buy_num": 1, "level_name": "高级", "money": 4680, "shengyu_lesson_num": 35, "free_lesson_num": 10, "mode_name": "陪练", "tuifei_num": 0, "modify_date": "2017-10-16 13:36:20", "lesson_min": 50, "shouci_buy_num": 0 }, { "type_name": "正课", "lesson_name": "标准陪练课(高级)-60节", "course_name": "标准陪练", "lesson_no": "BZ-c3-2", "lesson_num": 60, "lesson_id": 41, "xufei_buy_num": 1, "level_name": "高级", "money": 9180, "shengyu_lesson_num": 58, "free_lesson_num": 2, "mode_name": "陪练", "tuifei_num": 0, "modify_date": "2017-10-16 13:37:36", "lesson_min": 50, "shouci_buy_num": 0 }, { "type_name": "正课", "lesson_name": "标准陪练课(高级)-90节", "course_name": "标准陪练", "lesson_no": "BZ-c3-3", "lesson_num": 90, "lesson_id": 42, "xufei_buy_num": 0, "level_name": "高级", "money": 13480, "shengyu_lesson_num": 91, "free_lesson_num": 3, "mode_name": "陪练", "tuifei_num": 0, "modify_date": "2017-10-16 13:38:41", "lesson_min": 50, "shouci_buy_num": 1 }, { "type_name": "正课", "lesson_name": "标准陪练课(高级)-120节", "course_name": "标准陪练", "lesson_no": "BZ-c3-4", "lesson_num": 120, "lesson_id": 43, "xufei_buy_num": 0, "level_name": "高级", "money": 17080, "shengyu_lesson_num": 0, "free_lesson_num": 0, "mode_name": "陪练", "tuifei_num": 0, "modify_date": "2017-10-16 13:39:45", "lesson_min": 50, "shouci_buy_num": 0 }, { "type_name": "正课", "lesson_name": "标准陪练课(高级)-200节", "course_name": "标准陪练", "lesson_no": "BZ-c3-5", "lesson_num": 200, "lesson_id": 44, "xufei_buy_num": 0, "level_name": "高级", "money": 27680, "shengyu_lesson_num": 0, "free_lesson_num": 0, "mode_name": "陪练", "tuifei_num": 0, "modify_date": "2017-10-16 13:40:58", "lesson_min": 50, "shouci_buy_num": 0 }, { "type_name": "正课", "lesson_name": "标准陪练-20节", "course_name": "标准陪练", "lesson_no": "BZ-c0-02", "lesson_num": 20, "lesson_id": 64, "xufei_buy_num": 0, "level_name": "全级别", "money": 2000, "shengyu_lesson_num": 0, "free_lesson_num": 0, "mode_name": "陪练", "tuifei_num": 0, "modify_date": "2017-11-24 15:15:22", "lesson_min": 50, "shouci_buy_num": 0 }, { "type_name": "正课", "lesson_name": "标准陪练-5节", "course_name": "标准陪练", "lesson_no": "BZ-c0-01", "lesson_num": 20, "lesson_id": 63, "xufei_buy_num": 0, "level_name": "全级别", "money": 2000, "shengyu_lesson_num": 14, "free_lesson_num": 0, "mode_name": "陪练", "tuifei_num": 0, "modify_date": "2017-11-24 15:14:44", "lesson_min": 25, "shouci_buy_num": 1 } ] } }, computed: { needJsons: function () { let _this = this; this.jsons.forEach(function (item, index) { if (item.lesson_name === '标准陪练-5节') { _this.jsons.splice(index, 1); } }) return _this.jsons } } }) 不过还是推荐使用v-if 来达到目的
    请先 登录 后评论

注册新账号

悬赏追问
10
  • 10
  • 20
  • 50
  • 100
  • 200
  • 输入数值
发布追问