GithubHelp home page GithubHelp logo

loopback-tree-mixin's Introduction

TREE

This module is designed for the Strongloop Loopback framework. It adds lft and rgt attributes to any Model and a relations belongsTo to itself with name parent.

This module is implemented with the before save Operation Hook which is relatively new to the loopback framework so your loopback-datasource-juggler module must be greater than version 2.23.0.

INSTALL

  npm install --save loopback-tree-mixin

MIXINSOURCES

With [email protected] mixinSources have been implemented in a way which allows for loading this mixin without changes to the server.js file previously required.

Add the mixins property to your server/model-config.json like the following:

{
  "_meta": {
    "sources": [
      "loopback/common/models",
      "loopback/server/models",
      "../common/models",
      "./models"
    ],
    "mixins": [
      "loopback/common/mixins",
      "../node_modules/loopback-tree-mixin",
      "../common/mixins"
    ]
  }
}

CONFIG
=============

To use with your Models add the `mixins` attribute to the definition object of your model config.

```json
  {
    "name": "Category",
    "properties": {
      "name": {
        "type": "string",
      }
    },
    "mixins": {
      "Tree" : true
    }
  }

TESTING

You'll need jasmine-node globally installed to run the tests which can be installed with this command: npm install -g jasmine-node. This tool helps error checking.

Run the tests in tree-spec.js

  jasmine-node .

LICENSE

ISC

loopback-tree-mixin's People

Contributors

csbenjamin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

loopback-tree-mixin's Issues

Using the mixin in real life

Hi,
your concept is built on the nested sets model, correct? If so, how do you handle updating the tree, like moving a branch around? Also, how do you handle the rendering of the tree, into an Array for example?

Thank you

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.