write the handler

Write the process using Script

New scripts/category.js:

function category() {
var data = Process("models.category.get", {
wheres: [{ column: "parent_id", value: null }],
});
return data;
}
// Call other processes in JS and call the category method above
function getData() {
return Process("scripts.category.category");
}

Running the command line call yao run scripts.category.category is equivalent to yao run scripts.category.getData

Write a process with Flow

Create a new models/category.mod.json and write the following code:

View source code

Execute the command yao migrate -n category and you can see that the corresponding data table and data are generated in the database

Write flows/category.flow.json write the following code:

{
"label": "Category Tree",
"version": "1.0.0",
"description": "Category Tree",
"nodes": [
{
"name": "Category",
"engine": "xiang",
"query": {
"select": ["id", "name", "name as label", "id as value", "parent_id"],
"wheres": [{ ":deleted_at": "deleted", "=": null }],
"from": "category",
"limit": 1000
}
},
{
"name": "Category Tree",
"process": "xiang.helper.ArrayTree",
"args": ["{{$res.category}}", { "parent": "parent_id" }]
}
],
"output": "{{$res.category tree}}"
}

Execute yao run flows.category to see the following output in the console:

[
{
"children": [
{
"children": [],
"id": 2,
"label": "Secondary Classification",
"name": "Secondary Category",
"parent_id": 1,
"value": 2
}
],
"id": 1,
"label": "First-class classification",
"name": "First-level classification",
"parent_id": null,
"value": 1
}
]

write the handler

Write the process using Script

New scripts/category.js:

function category() {
var data = Process("models.category.get", {
wheres: [{ column: "parent_id", value: null }],
});
return data;
}
// Call other processes in JS and call the category method above
function getData() {
return Process("scripts.category.category");
}

Running the command line call yao run scripts.category.category is equivalent to yao run scripts.category.getData

Write a process with Flow

Create a new models/category.mod.json and write the following code:

View source code

Execute the command yao migrate -n category and you can see that the corresponding data table and data are generated in the database

Write flows/category.flow.json write the following code:

{
"label": "Category Tree",
"version": "1.0.0",
"description": "Category Tree",
"nodes": [
{
"name": "Category",
"engine": "xiang",
"query": {
"select": ["id", "name", "name as label", "id as value", "parent_id"],
"wheres": [{ ":deleted_at": "deleted", "=": null }],
"from": "category",
"limit": 1000
}
},
{
"name": "Category Tree",
"process": "xiang.helper.ArrayTree",
"args": ["{{$res.category}}", { "parent": "parent_id" }]
}
],
"output": "{{$res.category tree}}"
}

Execute yao run flows.category to see the following output in the console:

[
{
"children": [
{
"children": [],
"id": 2,
"label": "Secondary Classification",
"name": "Secondary Category",
"parent_id": 1,
"value": 2
}
],
"id": 1,
"label": "First-class classification",
"name": "First-level classification",
"parent_id": null,
"value": 1
}
]