Code Monkey home page Code Monkey logo

Comments (5)

overboy20 avatar overboy20 commented on May 23, 2024 1

Thank you @robinsandstrom, it helped me!

My mistake was in passing my component to each h function.

from vue-org-tree.

robinsandstrom avatar robinsandstrom commented on May 23, 2024
renderContent: function(h, data) {

  return h(MyVueComponent, {

    props: {

      foo: bar,

      bar: foo
    },
  });
}

Try this and you should be able to use any component as a node!

from vue-org-tree.

overboy20 avatar overboy20 commented on May 23, 2024

Thanks @robinsandstrom !

I am tried this

Component TreeNodePerson:

<template>
    <div class="class">
    </div>
</template>

<script>
    import store from "../store";

    export default {
        props:['className', 'width'],
        data() {
            return {
            }
        },
        mounted() {
        },
        methods: {
        },
        computed: {
            class () {
                return this.$props.className;
            }
        }
    }
</script>

and updated render function:

return h(TreeNodePerson, {
        props: {
            className: className
        }
    }, [h(TreeNodePerson, {
        props: {
            className: cls.join(' '),
            width: labelWidth,
        },
    }, childNodes)])

But unfortunately components are not rendering

from vue-org-tree.

robinsandstrom avatar robinsandstrom commented on May 23, 2024

<template>
  <section>
    <div class="content">
          <vue-org-tree
            :data="data"
            :props="dataprops"
            :horizontal="horizontal"
            :collapsable="collapsable"
            :render-content="renderContent"
            @on-expand="onExpand"
            @on-node-click="onNodeClick"/>
          </div>
        </div>
      </div>
    </div>
  </section>
</template>


<script>

import { mapGetters } from 'vuex'
import Node from '@/components/Node'

export default {
  components: { Node },
  data () {
    return {
      data: { 'name': 'Company 1', 'business_id': 10, children: [] },
      horizontal: true,
      collapsable: true,
      expandAll: true,
      labelClassName: 'bg-white',
      dataprops: {
        label: 'id',
        expand: 'expand',
        children: 'children'
      }
    }
  },
  methods: {
    renderContent: function(h, data) {
      return h(CompanyNode, {
        props: {
          label: data.name,
          value: data.business_id
        },
      });
    },
    onExpand: function(e, data) {
      if ('expand' in data) {
        data.expand = !data.expand

        if (!data.expand && data.children) {
          this.collapse(data.children)
        }
      } else {
        this.$set(data, 'expand', true)
      }
    },
    onNodeClick: function(e, data) {
      this.$router.push({ name: 'Business', params: { id: data.id }})
    },
    collapse: function(list) {
      var _this = this
      list.forEach(function(child) {
        if (child.expand) {
          child.expand = false
        }

        child.children && _this.collapse(child.children)
      })
    },
    expandChange: function() {
      this.toggleExpand(this.data, this.expandAll)
    },
    toggleExpand: function(data, val) {
      var _this = this
      if (Array.isArray(data)) {
        data.forEach(function(item){
          _this.$set(item, 'expand', val)
          if (item.children) {
            _this.toggleExpand(item.children, val)
          }
        })
      } else {
        this.$set(data, 'expand', val)
        if (data.children) {
          _this.toggleExpand(data.children, val)
        }
      }
    }
  }
}

</script>

With Node:

<template>
  <section>
    <div class="has-text-left">
      <p class="is-size-5 py-0 my-0 has-text-weight-medium has-text-black">{{ label }}</p>
      <p class="py-0 my-0 is-size-6 mt-0">{{ value }}</p>
    </div>
  </section>
</template>

<script>
export default {
  props: {
    label: String,
    value: String
  }
}
</script>

from vue-org-tree.

robinsandstrom avatar robinsandstrom commented on May 23, 2024

Great to hear :)

from vue-org-tree.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.