方法一:map()
let cities = [
{city:"北京",id:100000},
{city:"上海",id:20000},
{city:"广州",id:510000},
{city:"深圳",id:518000}];
let city = cities.map((item) =>{
return item.city
});
console.log(city);
方法二:foreach()或for()
let cities = [
{city:"北京",id:100000},
{city:"上海",id:20000},
{city:"广州",id:510000},
{city:"深圳",id:518000}
];
let city = []; cities.forEach((item)=>{
city.push(item.city); });
console.log('city == ',city);
cartTable.Map(x => {return x.resourceid}) 生成数组
let newArr = cartTable.Map((item, index) => {
return item.resourceid
var result =cartTable.map(function(item) {
return item.resourceid;
console.log(result)
});
console.log("arr的id集合", newArr)
vue forEach循环数组拿到自己想要的数据
<el-checkbox v-for="(item) in jurisdictionContent"
:label="item.id"
:key="item.id"
class="checkboxMargin">
<span>{{item.value}}{{item.checked}}</span>
</el-checkbox>
handleJurisdiction(index, row) {//获取权限
this.selectedCheck=[];
let me = this;
this.jurisdiction = true;
this.roleId = row.id;
this.$http.get("/role/resources", {
params: {roleId: this.roleId}
},
{
emulateJSON: true
}).then((response) => {
me.jurisdictionContent = response.body;
me.jurisdictionContent.forEach(function (c) {
if(c['checked']){
me.selectedCheck.push(c.id);
}
})
console.log(this.selectedCheck)
})
vue 中标签里循环使用v-for ,方法里面循环使用forEach
// that.tableData=tabled
// that.tabled.push({'content':[resp.data]})
// resp.data.(item)=>{tabled.push(item)};
// })
// forEach(
// axios.get('http://localhost:8182/resource/findById/',cartResourceId).then(function (resp) { // + _this.cartTable.resourceid调取后端数据,读取到页面相应窗口,+this.$route.query.id
// console.log(resp.data)
// alert("拿到数据")
// }
// )
// )
// _this.tabled
// let tableData = JSON.parse(JSON.stringify(tabled));