第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

vue.js 數(shù)組過濾二維數(shù)組的問題?

vue.js 數(shù)組過濾二維數(shù)組的問題?

紫衣仙女 2018-08-10 09:09:49
1.我的需求:在搜索框輸入內(nèi)容時能過濾出包含內(nèi)容的數(shù)據(jù),刪除內(nèi)容時能返回數(shù)據(jù)初始狀態(tài)       {A商品,B商品,C商品},{B商品}         搜索:'A'    返回:A商品;           退格:''     返回  {A商品,B商品,C商品},{B商品}2.數(shù)組結(jié)構(gòu):3.我的代碼:3.我的問題:在退格后不會返回數(shù)據(jù)初始狀態(tài).是因為進行了兩次filter的原因嗎?但我沒有修改原數(shù)組,而是修改遍歷復制的數(shù)組啊?若只對數(shù)組進行一次filter,退格是會返回初始狀態(tài)如:return arrs.filter(function(item){return item==1})希望能得到解決方案.謝謝!
查看完整描述

1 回答

?
慕斯王

TA貢獻1864條經(jīng)驗 獲得超2個贊

我認為你要對標題進行過濾的話直接把過濾器設置在每一個商品上比較好,沒必要對整個全部進行過濾處理,比如我這樣。也能實現(xiàn)業(yè)務場景。至于你的代碼的錯誤,我不太懂明白為什么在computed里定義methods,我也剛開始學,如果可以給下源碼,也想看看你的方法錯在哪

<template>

  <div class="hello">

    <input type="text" v-model="searchGood">

    <ul>

      <template v-for="arr in arrs " v-show='arr.showtr'>

        <li v-for="good in arr.goods | filterBy goodFilter">{{good.title}}</li>

      </template>

    </ul>

  </div>

</template>


<script>

  export default {

    data () {

      return {

        // note: changing this line won't causes changes

        // with hot-reload because the reloaded component

        // preserves its current state and we are modifying

        // its initial state.

        msg: 'Hello World!',

        searchGood: '',

        items: [

          {message: 'Foo'},

          {message: 'Bar'}

        ],

        arrs: [

          {

            goods: [{

              title: 'A標題'

            }, {

              title: 'B標題'

            }, {

              title: '這是標題'

            }],

            orderNo: '111111111111',

            showtr: true

          },

          {

            goods: [{

              title: 'AA標題'

            }, {

              title: 'BB標題'

            }],

            orderNo: '222222222222',

            showtr: true

          }]

      }

    },

    methods: {

      goodFilter (good) {

        if (this.searchGood === '') {

          return true

        }

        if (good.title.indexOf(this.searchGood) !== -1) {

          return true

        } else {

          return false

        }

      }

    }

  }

</script>


<!-- Add "scoped" attribute to limit CSS to this component only -->

<style scoped>

  h1 {

    color: #42b983;

  }

</style>


查看完整回答
反對 回復 2018-09-27
  • 1 回答
  • 0 關(guān)注
  • 2236 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號