Avoid using non-primitive value as key, use string/number value instead. in VueJS

时间:2017-12-18 06:57:19

标签: javascript vue.js vuejs2

I'm trying to build an application where I'm trying to get values, everything was working fine,

Here is my code: https://codeshare.io/aY7rX3

But suddenly some error started coming:

Avoid using non-primitive value as key, use string/number value instead

Somewhere around:

<div class="col-sm-4 border-right">
    <div>
        <button @click.prevent="" v-for="(obj, key) in tags"
                :key="key"
                class="btn btn-rounded btn-sm"
                :class="tagParentClass(key)">
            {{key}}
        </button>
    </div>
</div>

The data set of tags

export const tags = {
    Investor: [
        {display: "Mutual Fund", value: 'Mutual Fund'},
        {display: "Insurance", value: 'Insurance'},
        {display: "FII", value: 'FII'},
        {display: "PMS", value: 'PMS'},
        {display: "Proprietary", value: 'Proprietary'},
        {display: "HNI", value: 'HNI'},
        {display: "Private Equity", value: 'Private Equity'},
        {display: "Others", value: 'Others'}
    ],
    Research: [
        {display: "Global", value: 'Global'},
        {display: "Domestic", value: 'Domestic'},
        {display: "Retail", value: 'Retail'},
        {display: "Others", value: 'Others'}
    ],
    Corporate: [
        {display: "Corporate", value: 'Corporate'}
    ],
    Others: [
        {display: "Debt", value: 'Debt'},
        {display: "Debt Adviser", value: 'Debt Adviser'},
        {display: "Investment Banker", value: 'Investment Banker'},
        {display: "Media", value: 'Media'},
        {display: "Others", value: 'Others'}
    ]
}

Help me out in this.

2 个答案:

答案 0 :(得分:0)

Try changing the JSON format of tags.
The warning message will disappear if you modify your JSON Format to below format

sql = "CREATE TABLE tab (ID INTEGER PRIMARY KEY," + ",".join(matFile) + ")"

Updated:

i have updated your JSON format to a more friendlier JSON Format that is used in most usecases.
Try this approach and let me know if it works

Template

[{
    Investor: [
        {display: "Mutual Fund", value: 'Mutual Fund'},
        {display: "Insurance", value: 'Insurance'},
        {display: "FII", value: 'FII'},
        {display: "PMS", value: 'PMS'},
        {display: "Proprietary", value: 'Proprietary'},
        {display: "HNI", value: 'HNI'},
        {display: "Private Equity", value: 'Private Equity'},
        {display: "Others", value: 'Others'}
    ]
    },
   { 
     Research: [
        {display: "Global", value: 'Global'},
        {display: "Domestic", value: 'Domestic'},
        {display: "Retail", value: 'Retail'},
        {display: "Others", value: 'Others'}
    ]
    },
   { 
     Corporate: [
        {display: "Corporate", value: 'Corporate'}
    ]
    },
    {
      Others: [
        {display: "Debt", value: 'Debt'},
        {display: "Debt Adviser", value: 'Debt Adviser'},
        {display: "Investment Banker", value: 'Investment Banker'},
        {display: "Media", value: 'Media'},
        {display: "Others", value: 'Others'}
    ]
    }
  ]

Script

<div v-for="(obj,index) in tags" :key="index">
              {{index}} {{obj.topic}}
        <div style="padding-left: 20px;" v-for="(category,index1) in obj.category" :key="index1">
                {{index1}} == {{category.display}} || {{category.value}}
              </div>
          </div>

答案 1 :(得分:-2)

在对象tags中,您在数组中嵌套了对象

如果您想要传递所有tags

&#13;
&#13;
let tags  = {
    Investor: [
        {display: "Mutual Fund", value: 'Mutual Fund'},
        {display: "Insurance", value: 'Insurance'},
        {display: "FII", value: 'FII'},
        {display: "PMS", value: 'PMS'},
        {display: "Proprietary", value: 'Proprietary'},
        {display: "HNI", value: 'HNI'},
        {display: "Private Equity", value: 'Private Equity'},
        {display: "Others", value: 'Others'}
    ],
    Research: [
        {display: "Global", value: 'Global'},
        {display: "Domestic", value: 'Domestic'},
        {display: "Retail", value: 'Retail'},
        {display: "Others", value: 'Others'}
    ],
    Corporate: [
        {display: "Corporate", value: 'Corporate'}
    ],
    Others: [
        {display: "Debt", value: 'Debt'},
        {display: "Debt Adviser", value: 'Debt Adviser'},
        {display: "Investment Banker", value: 'Investment Banker'},
        {display: "Media", value: 'Media'},
        {display: "Others", value: 'Others'}
    ]
}

new Vue({
  el: '#app',
  data: {
    tags 
  }
})
&#13;
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<div id="app">
  <div class="col-sm-4 border-right">
    <div v-for="(tag, key) in tags">{{key}}
        <button @click.prevent="" 
                v-for="key in tag"
                :key="key">
            {{key.value}}
        </button>
    </div>
  </div>
</div>
&#13;
&#13;
&#13;