to_graph_object()
Usage
to_graph_object(source [, view = 'public' [, depth = 3]])
Description
Tries to convert given object or collection containing graph objects into a graph object. If an element in the source can not be converted to a graph object, it is ignored.
Graph objects can be used in repeaters for example and thus it can be useful to create custom graph objects for iteration in such contexts.
The optional view
parameter can be used to select the view representation of the entity. If no view is given, the public
view is used.
The optional depth
parameter defines at which depth the conversion stops. If no depth is given, the default value of 3 is used.
Note: Since strings can not be converted to graph objects but it can be desirable to use collections of strings in repeaters (e.g. the return value of the inheriting_types()
function), collections of strings are treated specially and converted to graph objects with value
=> <string>
as its result. (see example 2)
Example 1
${{
var coll = Structr.to_graph_object([
{id:"o1",name:"objectA"},
{id:"o2",name:"objectB"}
]);
coll.forEach(function(n){Structr.print(n.name + '\n');});
}}
results in
objectA
objectB
Example 2
${
to_graph_object(inheriting_types('DOMNode'))
}
results in
[{value=DOMNode}, {value=DOMElement}, {value=Small}, {value=A}, {value=B}, {value=G}, {value=I}, {value=Abbr}, {value=P}, {value=Q}, {value=S}, {value=U}, {value=Output}, {value=Br}, {value=Audio}, {value=Dd}, {value=Dl}, {value=Dt}, {value=Video}, {value=Form}, {value=Em}, {value=Component}, {value=ShadowDocument}, {value=DocumentFragment}, {value=Thead}, {value=H1}, {value=H2}, {value=H3}, {value=H4}, {value=H5}, {value=H6}, {value=Nav}, {value=Hr}, {value=Fieldset}, {value=Style}, {value=Menu}, {value=Col}, {value=Keygen}, {value=Li}, {value=Option}, {value=Ruby}, {value=Datalist}, {value=Ol}, {value=Meta}, {value=Head}, {value=Code}, {value=Details}, {value=Blockquote}, {value=Rp}, {value=Rt}, {value=Figure}, {value=Select}, {value=Pre}, {value=Label}, {value=Td}, {value=Th}, {value=Tr}, {value=Ul}, {value=Mark}, {value=Wbr}, {value=Base}, {value=Object}, {value=Tbody}, {value=Article}, {value=Span}, {value=Textarea}, {value=Hgroup}, {value=Input}, {value=Html}, {value=Del}, {value=Summary}, {value=LinkSource}, {value=Dfn}, {value=Button}, {value=Link}, {value=Bdi}, {value=Bdo}, {value=Div}, {value=Footer}, {value=Iframe}, {value=Area}, {value=Samp}, {value=Optgroup}, {value=Colgroup}, {value=Command}, {value=Param}, {value=Address}, {value=Figcaption}, {value=Map}, {value=Embed}, {value=Cite}, {value=Template}, {value=Cdata}, {value=Noscript}, {value=Kbd}, {value=Body}, {value=Comment}, {value=Caption}, {value=Track}, {value=Tfoot}, {value=Sub}, {value=Sup}, {value=Header}, {value=Progress}, {value=Section}, {value=Page}, {value=Strong}, {value=Canvas}, {value=Time}, {value=Aside}, {value=Title}, {value=Meter}, {value=Var}, {value=Legend}, {value=Table}, {value=Script}, {value=Img}, {value=Content}, {value=Source}, {value=Ins}]