Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use this plugin in React component ? #40

Open
swetansh opened this issue Sep 8, 2020 · 2 comments
Open

How to use this plugin in React component ? #40

swetansh opened this issue Sep 8, 2020 · 2 comments

Comments

@swetansh
Copy link

swetansh commented Sep 8, 2020

I tried using this https://reactjs.org/docs/integrating-with-other-libraries.html to integrate this plugin in React but it didn't helped.
Aslo I tried https://medium.com/@shuvohabib/using-jquery-in-react-component-the-refs-way-969de9aa651f too but this shows error.
TypeError: this.$el.comboTree is not a function

My code looks like this -


import React, { Component } from "react";
import _ from "lodash";
import { findDOMNode } from "react-dom";
import $ from "jquery";

var SampleJSONData = [
  {
    id: 0,
    title: "Horse",
  },
  {
    id: 1,
    title: "Birds",
    isSelectable: false,
    subs: [
      {
        id: 10,
        title: "Pigeon",
        isSelectable: false,
      },
      {
        id: 11,
        title: "Parrot",
      },
      {
        id: 12,
        title: "Owl",
      },
      {
        id: 13,
        title: "Falcon",
      },
    ],
  },
  {
    id: 2,
    title: "Rabbit",
  },
  {
    id: 3,
    title: "Fox",
  },
  {
    id: 5,
    title: "Cats",
    subs: [
      {
        id: 50,
        title: "Kitty",
      },
      {
        id: 51,
        title: "Bigs",
        subs: [
          {
            id: 510,
            title: "Cheetah",
          },
          {
            id: 511,
            title: "Jaguar",
          },
          {
            id: 512,
            title: "Leopard",
          },
        ],
      },
    ],
  },
  {
    id: 6,
    title: "Fish",
  },
];

class SearchTreeView extends Component {
  componentDidMount() {
    const el = findDOMNode(this.refs.justAnotherInputBox);
    $(el).comboTree({
      source: SampleJSONData,
      isMultiple: false,
    });
  }

  render() {
    return (
      <div>
        <input
          type="text"
          id="justAnotherInputBox"
          placeholder="Type to filter"
          autocomplete="off"
          ref="justAnotherInputBox"
        />
      </div>
    );
  }
}

export default SearchTreeView;
@swetansh
Copy link
Author

swetansh commented Sep 8, 2020

Please help to integrate this to react

@swetansh
Copy link
Author

swetansh commented Sep 8, 2020

Tried this one too but this is also showing error.

import React, { Component } from "react";
import _ from "lodash";
import { findDOMNode } from "react-dom";
import $ from "jquery";

var SampleJSONData = [
  {
    id: 0,
    title: "Horse",
  },
  {
    id: 1,
    title: "Birds",
    isSelectable: false,
    subs: [
      {
        id: 10,
        title: "Pigeon",
        isSelectable: false,
      },
      {
        id: 11,
        title: "Parrot",
      },
      {
        id: 12,
        title: "Owl",
      },
      {
        id: 13,
        title: "Falcon",
      },
    ],
  },
  {
    id: 2,
    title: "Rabbit",
  },
  {
    id: 3,
    title: "Fox",
  },
  {
    id: 5,
    title: "Cats",
    subs: [
      {
        id: 50,
        title: "Kitty",
      },
      {
        id: 51,
        title: "Bigs",
        subs: [
          {
            id: 510,
            title: "Cheetah",
          },
          {
            id: 511,
            title: "Jaguar",
          },
          {
            id: 512,
            title: "Leopard",
          },
        ],
      },
    ],
  },
  {
    id: 6,
    title: "Fish",
  },
];

class SearchTreeView extends Component {
  componentDidMount() {
    this.$el = $(this.el);
    this.$el.comboTree({
        source: SampleJSONData,
        isMultiple: false,
    });
  }

  render() {
    return (
      <div>
        <input
          type="text"
          id="justAnotherInputBox"
          placeholder="Type to filter"
          autocomplete="off"
          ref={el => this.el = el}
        />
      </div>
    );
  }
}

export default SearchTreeView;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant