Need Help on Template Maps

Hi Team,

I am designing node templates on the basis of Type.

Like Type = sample --> node template will be diff

As per Go JS documentation it is using category for differentiate.

Can we use our own type for example i have type = sample or type = complex?

I want to use Type in place of category.

I this case is there any workaround to fit solution?

Thanks

Set https://gojs.net/latest/api/symbols/Model.html#nodeCategoryProperty to the data property name that you want to use instead of “category”.

Thanks walter,

Can you tell where exactly i need to set this property?

On your Model instance.

thanks a lot walter.

this works!!!

myDiagram.model.nodeCategoryProperty = “Type”;

Hi walter,

is it possible to design template on two diff properties ?

for example currently doing it using Type, I need to add id as well for designing.

Thanks

Could you please give an example of what you mean?

Currently I am designing templates on one property - Type,

As our scenario get changed, I need to design template on two diff properties

Like myDiagram.model.nodeCategoryProperty = “Type”;

I need to add one more - myDiagram.model.nodeCategoryProperty = “Id".

So it should work on the basic of “Type and Id” ?

Could give an example please?

If you can define a function that takes the node data object and returns the category name, that could be used as the value for Model.nodeCategoryProperty: https://gojs.net/latest/api/symbols/Model.html#nodeCategoryProperty

Not sure, if you understand my question?

I don’t have any example.

As per current gojs documentation https://gojs.net/latest/intro/templateMaps.html
we have option to design using one property like .

var templatemap = new go.Map();
templatemap.add(“create”, createTemplate);
templatemap.add(“link”, linkTemplate);

myDiagram.nodeTemplateMap = templatemap;
myDiagram.layout = $$(go.TreeLayout, { angle: 90, alignment: go.TreeLayout.AlignmentStart });

Here create , link are types.

Consider i have one more condition - id of node.

so the template will design on the basis of type and id .

is it possible ?

Thanks

I updated my previous reply. You have given some example names for the templates, but I was also looking for an example node data object.

Your function should take one parameter, the data object, and return a string, either “create” or “link”.

in simple way its like and condition.

template should come on the basis of two parameters .

Select template from list where type = “Create” and id = “4444”;

Currently i have it using only one parameter like type=“create”

Try what I suggested. Be sure to read its documentation first.