我有一个包含员工详细信息以及其主管ID的数组,我必须构建组织结构图以表示报表层次结构,因为我需要多维数组中的数组,我尝试了多种方法,但无法按要求进行构建。有人请我帮我解答。
import Vue from 'vue'
import App from './App'
import router from './router'
import { store } from './store/store'
import firebase from './firebase-config'
import vuefire from 'vuefire'
//////////////// HERE
import VueRangedatePicker from 'vue-rangedate-picker' // importing the plugin here
Vue.use(VueRangedatePicker) // using it
Vue.component('VueRangedatePicker', { }) // creating the component globally (if I don't add this line the app complains the component is not registered
////////////////
Vue.config.productionTip = false
let app;
Vue.use(vuefire)
firebase.auth().onAuthStateChanged(function(user){
if (!app) {
/* eslint-disable no-new */
app = new Vue({
el: '#app',
template: '<App/>',
components: { App, VueRangedatePicker },
router,
store,
VueRangedatePicker
})
}
})
现在我必须像下面这样在分层模式下转换该数组
<template>
<div>
<vue-rangedate-picker @selected="onDateSelected" i18n="EN" />
</div>
</template>
<script>
import firebase,{ itemRef } from '../firebase-config';
import VueRangedatePicker from 'vue-rangedate-picker'
export default {
firebase() {
return {
items: itemsRef,
}
},
name: 'component_A',
data () {
return {
}
},
created() {
console.log(VueRangedatePicker);
},
methods: {
onDateSelected: function (daterange) {
this.selectedDate = daterange
},
}
</script>
我为每个循环写了两个,但这给了我直到第二次的结果。预先感谢您的回答。这是我尝试过的代码。
Array
(
[0] => stdClass Object
(
[userID] => 336
[fullName] => S G
[employeeSupervisiorID] => 316
[employeePhoto] => 1537274919.jpg
)
[1] => stdClass Object
(
[userID] => 316
[fullName] => S J
[employeeSupervisiorID] => 1
[employeePhoto] => 1537274885.jpg
)
[2] => stdClass Object
(
[userID] => 337
[fullName] => R K
[employeeSupervisiorID] => 316
[employeePhoto] => 1537274940.jpg
)
[3] => stdClass Object
(
[userID] => 405
[fullName] => De B
[employeeSupervisiorID] => 1
[employeePhoto] => 1537274961.jpg
)
[4] => stdClass Object
(
[userID] => 418
[fullName] => J D
[employeeSupervisiorID] => 337
[employeePhoto] => 1537274978.jpg
)
[5] => stdClass Object
(
[userID] => 420
[fullName] => A S
[employeeSupervisiorID] => 316
[employeePhoto] => 1537274997.jpg
)
[6] => stdClass Object
(
[userID] => 421
[fullName] => Sanjay j
[employeeSupervisiorID] => 1
[employeePhoto] => 1537275044.png
)
[7] => stdClass Object
(
[userID] => 423
[fullName] => Test User
[employeeSupervisiorID] => 336
[employeePhoto] => 1537275091.jpg
)
)
答案 0 :(得分:1)
请参考以下示例来构建组织结构图。
function buildChart($empArr, $parentId = 0) {
$result = array();
foreach ($empArr as $emp) {
if ($emp['employeeSupervisiorID'] == $parentId) {
$children = buildChart($empArr, $emp['userID']);
if ($children) {
$emp['children'] = $children;
}
$result[] = $emp;
}
}
return $result;
}
$tree = buildChart($empArr);