I have an object called main and its one of the item, data: , points to an array defined as submenuitem. When user clicks on something, the UI gets updated with array items in submenuitems. It also updates the topbar to display the title of current menu which is basically the variable name SUBMENUITEMS.
Can anyone tell how can I get the submenu item variable name data: "--->this<--" as String?
let submenuItems = ["subMenu 1","subMenu 2","subMenu 3","subMenu 4","subMenu 5","subMenu 6"];
let main = {
title:'main menu',
menuLogo:'img/logo1.png',
data:submenuItems
}
Edit:
I see a lot of confusion. Actually this a part of my code which is written using Vuejs -
<div v-for="(item,index) in dataArray" v-on:click="subMenu(item)" v-bind:id="'tile_'+index" class="card">
<div><img v-bind:src=item.menuLogo onerror="this.src='img/default.svg'" /></div>
<div>{{item.title}}</div>
<div>{{index+1}}</div>
</div>
let subhome = [
{"title":"sub_card_title","sub_cardimage":"sub_item1.png",data:[]},
{"title":"sub_card_title","sub_cardimage":"sub_item1.png",data:[]}, {"title":"sub_card_title","sub_cardimage":"sub_item1.png",data:[]},`
{"title":"sub_card_title","sub_cardimage":"sub_item1.png",data:[]}
]
let home = [
{"title":"card_title","cardimage":"item1.png",data:[]},
{"title":"card_title","cardimage":"item1.png",data:subhome}, {"title":"card_title","cardimage":"item1.png",data:[]},`
{"title":"card_title","cardimage":"item1.png",data:[]}
]
let menu = new Vue({
el: '#menu',
data: {
dataArray: home
},
methods: {
subMenu: function(item) {
if (item.data.length > 0) {
this.dataArray = item.data;
console.log('sub menu array -->', this.dataArray);
$('#menu-title').text(eval(item));
}
},setTitle: function(val) {
let title = eval(val); // <---- how to vaiable name of data array
$('#spancontainer').text(title)
}
}
});