tabs.forEach((v,i)=>i===index?v.isActive=true:v.isActive=false)
collect数组对象下的值进行条件判断并修改属性值 goods_id数组对象属性,v数组对象,有一个满足的查询到了返回true
collect.some(v =>v.goods_id === this.GoodsInfo.goods_id)
//every必须每个都满足 否则是false
Array.every()
写个函数,也是来自于tp官方function list_to_tree($list, $pk='id', $pid = 'pid', $child = '_child', $root = 0) {
// 创建Tree
$tree = array()
if(is_array($list)) {
// 创建基于主键的数组引用
$refer = array()
foreach ($list as $key =>$data) {
$refer[$data[$pk]] =&$list[$key]
}
foreach ($list as $key =>$data) {
// 判断是否存在parent
$parentId = $data[$pid]
if ($root == $parentId) {
$tree[] =&$list[$key]
}else{
if (isset($refer[$parentId])) {
$parent =&$refer[$parentId]
$parent[$child][] =&$list[$key]
}
}
}
}
return $tree
}
然后定义一维数组为$list,然后 print_r(list_to_tree($list,"id","parentsid","subnav"))
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)