I have List Of object of Element class where Element's object are like:
1.element1{
name : "riya",
child: false,
parentName :null
},
2.element2{
name : "kiya",
child: true,
parentName :"riya"
},
3.element3{
name : "veera",
child: false,
parentName :null
},
4.element1{
name : "sanam",
child: true,
parentName :"kiya"
}
Parent object are those whose child attribute have false value, while child object are those whose child attribute are true and parent name is described in parentName attribute.
How can i sort this List so that child always followed by their parent.
Related
Given data with unknown structure, I would like to find all instances of 'label'.
{
label: 'test',
...,
child: {
label: 'another test',
...,
child: {
label: 'more info',
...,
},
child: {
no-label: 'I do not have a label field',
...,
}
},
}
I would like to return something like the above, just w/out the "other" fields because I would need to know "where" the labels are. The trick is that not all items or children will have a label and the specific structure is unknown at query time. (there may or may not be children on any item, etc.)
I need to be able to create a catalog for a given entity and then somewhere in the grandchildren I want to use the catalog IDs and resolve them.
think of this (very simplified) data model
type Entity {
id: ID
componentCatalog: [Component]
child: Child
}
type Child {
grandChildren: [GrandChild]
}
type GrandChild {
components: [Component]
}
in the NoSQL db I would store this as:
{
id: 'abc',
componentCatalog: [ { id: 1, title: 'a' }, { id: 2, title: 'b' }],
child: {
grandChildren: [
{
componentIds: [1]
},
{
componentIds: [1,2]
}
]
}
}
and I would like to resolve the IDs to the components that are stored in the catalog of the Entity
however how do I get to the data from the grandchildren? Parent is just a child, do I have to save the catalog into the GQL context? If so then how? If there are multiple entities in the query how do I know which Grandchild belongs to which entity?
Thanks a lot in advance
I am new to angular 9. I want show the mat-cards as parent and child with graph. Below is the data
[
{ "id" : "ajson1", "parent" : "#", "text" : "Simple root node" },
{ "id" : "ajson2", "parent" : "#", "text" : "Root node 2" },
{ "id" : "ajson3", "parent" : "ajson2", "text" : "Child 1" },
{ "id" : "ajson4", "parent" : "ajson2", "text" : "Child 2" },
]
Based on the below picture i have to show the mat-card with graphical view
Is there any npm package available? Or is it possible show like this? i tried with swimlane but i can't.
To render flat data as a hierarchy you can use component recursion. Each node will render all its children, which will render the next level of children, etc.
Because there are multiple root nodes, start by having the container component render each top-level item:
get rootNodes(): TreeNode[] {
return this.nodes.filter(node => node.parent === '#');
}
<app-tree *ngFor="let node of rootNodes"
[nodes]="nodes"
[nodeId]="node.id">
</app-tree>
Then each of those components will render any child nodes using the same component. Because the data is flat, we pass all the list items to each tree component and let that component sort out which items to render.
#Component({
selector: 'app-tree',
...
})
export class TreeComponent {
#Input() nodes: TreeNode[];
#Input() nodeId: string;
get childNodes(): TreeNode[] {
return this.nodes.filter(node => node.parent === this.nodeId);
}
}
<!-- Render the item itself, e.g. using a mat-card -->
<h1>{{nodeId}}</h1>
<!-- Render each child -->
<app-tree *ngFor="let childNode of childNodes"
[nodes]="nodes"
[nodeId]="childNode.id">
</app-tree>
Representing the hierarchy is then a matter of styling, such as using padding to indent each level.
Also, if your data changes after the initial render you may want to use the *ngFor trackBy to reduce the required DOM changes.
Demo StackBlitz
I have created "blogs" table with id(primary key), title ,created at ,updated at , status (with enum type having values "active,inactive,hidden" with default value "active")
create function on Blog Model is working fine when giving status value from above mentioned set of values and empty value
const Blog = sequelize.define('blog', { id: { type:
Sequelize.INTEGER,
primaryKey: true, autoIncrement: true }, text: Sequelize.STRING,
status : { type : Sequelize.ENUM, allowNull : false, values :
['Inactive','Active','Hidden'], defaultValue : 'Active' } });
Blog.create({"title" :"hello","status":"abc"}).then(result => {
console.log(result);
});
The above code inserted a new record in blogs table with status of empty value.but result object having status of "abc".How can I get newly inserted record ?
You should define ENUM like this:
status : {
type : Sequelize.ENUM('Inactive','Active','Hidden'),
allowNull : false,
defaultValue : 'Active',
validate: {
isIn: {
args: [['Inactive','Active','Hidden']],
msg: "Wrong status"
}
}
}
In order to validate enum values you can use per attribute validation
`My oracle database and getting Tree-panel :
Now I would like to display database table from column2 asa each
Parent Node as Child Node please let me know how could I make it also
my Json Data I am getting result like that please let me know how could I get child node ?
My Expected result like :
This is the JSON data :
[{
"id":1,"reportTreeType":0,"text":"Root","reportType":null,"reportUrl":"", "hidden":false,
"children":[{
"id":5,"reportTreeType":0,"text":"Hardware","reportType":"HardReport","reportUrl":"","hidden":false,"children":[], "leaf":false,"dirName":"","href":"","reportId":0,"qtip":""}]
I have tried ExtJS Tree-Panel below like but I am getting from table-1 column1 parent node not getting column2 child nodes ?
Ext
.onReady(function() {
var tree = new Ext.tree.TreePanel(
{id : 'treePanel',
el : 'tree-div',
useArrows : true,
title : 'Export',
autoScroll : true,
width : 250,
region : 'west',
animate : true,
enableDD : true,
containerScroll : true,
enableKeyEvents : true,
collapsible : true,
split : true,
rootVisible : false,
border : false,
// auto create TreeLoader
dataUrl :'<c:url value="/customize/ExportReport.do?method=getExport"/>',
root : {
nodeType : 'async',
text : 'Root',
draggable : false,
id : '-1',
expanded:true,
//here Children node I cannot able to rendered where I have made mistake ?
children:[{
text: reportType, //TreeNode Java class variable
leaf: true }]
}
} }); });
If I understand well, you would like that Hardware is a child of Root and HardReport a child of Hardware.
I think there is no direct solution in ExtJs.
you change your backend to send the correct data
you have to manually parse the JSON
you load the data in a first tree store, and then you build a second tree store by looping through the first.