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 get data with state from tree? #29

Closed
ghost opened this issue Jul 2, 2018 · 6 comments
Closed

How to get data with state from tree? #29

ghost opened this issue Jul 2, 2018 · 6 comments

Comments

@ghost
Copy link

ghost commented Jul 2, 2018

Hello,
is there a possibility to save the changed state in a json from the tree?
For example I have a predefined tree with no checked node. How can I get the data json with the checked nodes?
Best Regards

@amsik
Copy link
Owner

amsik commented Jul 2, 2018

Hello, I hope it will help you: #19.
If not please let me know.

@ghost
Copy link
Author

ghost commented Jul 2, 2018

Thanks, the function toJSON gives me the data I want.
Is there a function to filter the state? In my project I only need the state "checked" and "indeterminate".

@amsik
Copy link
Owner

amsik commented Jul 2, 2018

You can use either https://amsik.github.io/liquor-tree/#Tree-find-criteria-multiple-false or filter method of vanilla js

@ghost
Copy link
Author

ghost commented Jul 5, 2018

I wrote a function for JSON.stringify to extract the needed states.

var replace = function(key, value) {
  switch (key) {
    case "selected":
    case "selectable":
    case "expanded":
    case "disabled":
    case "visible":
    case "matched":
    case "editable":
    case "data":
      return undefined;
      break;
     case "children":
       if (value.length > 0) {
         return value;
       } else {
         return undefined;
       }
       break;
     default:
       return value;
  }
};
var treeModel = JSON.stringify(this.$refs.tree.toJSON(), replace);

This works fine to get a JSON String with the needed information.

Other question:
Which data can be stored in the data object in the data property of a tree node? Is it possible to put other information which are not relevant to the tree node expected data?

@amsik
Copy link
Owner

amsik commented Jul 5, 2018

The property data is a single object on node. You can put any data to this object :)

@ghost
Copy link
Author

ghost commented Jul 5, 2018

Thanks for your help :-) 👍

@ghost ghost closed this as completed Jul 5, 2018
This issue was closed.
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