Javascript 如何循环JSON数据
我有一个Javascript 如何循环JSON数据,javascript,vue.js,Javascript,Vue.js,我有一个json数据,我想从中使用vue.js制作Navbar,我无法通过Navbar循环数据 这就是我试图对JSON数据所做的,目前它是静态的,但我想循环使用我拥有的数据 由于我的JSON数据是动态的,我从后端获得,我必须根据用户登录名制作一个导航栏,向他/她显示允许的任何内容 我的JSON数据 { "Dashboard": [ { "type": "Dashboard", "link": "Dashboard.html" } ],
json
数据,我想从中使用vue.js
制作Navbar
,我无法通过Navbar
循环数据
这就是我试图对JSON数据所做的,目前它是静态的,但我想循环使用我拥有的数据
由于我的JSON
数据是动态的,我从后端获得,我必须根据用户登录名制作一个导航栏,向他/她显示允许的任何内容
我的JSON数据
{
"Dashboard": [
{
"type": "Dashboard",
"link": "Dashboard.html"
}
],
"Graphical Reports": [
{
"type": "Outlet Sales Summary Pai chart",
"link": "Outlet Sales Summary Pai chart.html"
},
{
"type": "Payment mode wise Graph layout",
"link": "Payment mode wise Graph layout.html"
},
{
"type": "Outlet wise Sales Area Chart",
"link": "AreaChart.html"
},
{
"type": "Outlet wise Sales Line Chart",
"link": "LineChart.html"
},
{
"type": "Top 20 Sold Items",
"link": "Top20Items.html"
},
{
"type": "Outlet Wise Quantity And Amount",
"link": "OutletWiseQuantityandAmount.html"
}
],
"Tabular Reports": [
{
"type": "Date wise Outlet wise Sales Summary",
"link": "Date wise Outlet wise Sales Summary.html"
},
{
"type": "Date wise OL Wise Counter wise Sales",
"link": "Date wise OL Wise Counter wise Sales.html"
},
{
"type": "Hourly wise Sales Bet Dates",
"link": "Hourly wise Sales Bet Dates.html"
},
{
"type": "Outlet wise Date wise NoOfBills",
"link": "Date Wise Ol Wise Bill Count.html"
},
{
"type": "Hourly sales Outlet wise Date wise",
"link": "Hourly sales Outlet wise Date wise.html"
},
{
"type": "Percentage Contribution Outlet wise",
"link": "PercentageolWise.html"
},
{
"type": "Outlet wise Item wise Sales With Date",
"link": "MRPL Store Sales With Date.html"
}
],
"Drill down Reports": [
{
"type": "Sales Drilldown Counterwise Bet Dates",
"link": "Sales Drilldown Counterwise Bet Dates.html"
},
{
"type": "Sales Drilldown Billwise Bet Dates",
"link": "Sales Drilldown Billwise Bet Dates.html"
},
{
"type": "Sales Drilldown Itemwise for Date",
"link": "Sales Drilldown Itemwise for Date.html"
},
{
"type": "Linked Sales Report Bet Dates",
"link": "LinkingReport.html"
}
],
"Masters": [
{
"type": "Item Master",
"link": "ItemMaster.html"
}
],
"Setup": [
{
"type": "Change Password",
"link": "ChangePassword.html"
},
{
"type": "User Admin",
"link": "UserAdmin.html"
}
],
"Transactions": [
{
"type": "Indent Request",
"link": "IndentWithCategoryWiseFilter.html"
}
]
}
newvue({
el:“#应用程序”,
数据(){
返回{
导航数据:{
“设置”:[{
“菜单”:“子菜单-1”
},
{
“路线”:“子菜单-2”
}
],
“报告”:[{
“菜单”:“子报告-1”
},
{
“路线”:“子报告-2”
}
]
}
}
},
})
Vue.config.productionTip=false;
Vue.config.devtools=false代码>
-
var arr=[{“id”:“10”,“class”:“child-of-9”},{“id”:“11”,“classd”:“child-of-10”}];
对于(变量i=0;i
尝试下面的代码片段:
-
新Vue({
el:“#应用程序”,
数据(){
返回{
导航数据:{
“设置”:[{
“菜单”:“子菜单-1”
},
{
“路线”:“子菜单-2”
}
],
“报告”:[{
“菜单”:“子报表-1”
},
{
“路线”:“子报告-2”
}
]
}
}
},
})
Vue.config.productionTip=false;
Vue.config.devtools=false;
您对输出的期望是什么?请始终将答案放在上下文中,而不仅仅是粘贴代码。有关更多详细信息,请参阅。
var arr = [ {"id":"10", "class": "child-of-9"}, {"id":"11", "classd": "child-of-10"}];
for (var i = 0; i < arr.length; i++){
var obj = arr[i];
for (var key in obj){
var attrName = key;
var attrValue = obj[key];
}
}