简体   繁体   English

Umbraco - 以编程方式通过ID获取节点

[英]Umbraco - Get Node by ID programmatically

Running Umbraco 4x I am creating a helper method in C# that I can recursively call to create child categories of a particular node (category). 运行Umbraco 4x我在C#中创建一个帮助器方法,我可以递归调用以创建特定节点(类别)的子类别。

The method takes a parentNodeID as a parameter. 该方法将parentNodeID作为参数。 I need to retrieve the properties of that parent node. 我需要检索该父节点的属性。 I know I can use the static method Node.GetCurrent() but I'm looking for something like Node.GetNodeById(parentNodeID). 我知道我可以使用静态方法Node.GetCurrent()但我正在寻找类似Node.GetNodeById(parentNodeID)的东西。

I just can't see where this method lives. 我只是看不出这种方法的存在。 I know there is the umbraco.library.getNodeXMLbyId method, but does that give me the name property of the node? 我知道有umbraco.library.getNodeXMLbyId方法,但这是否给了我节点的name属性?

Me Umbraco N00b :) 我Umbraco N00b :)

You can just do 你可以这样做

var node = new Node(nodeId).

Took me a while to find it too! 我花了一段时间才找到它!

Use this 用这个

umbraco.NodeFactory.Node headerNode = uQuery.GetNode(NodeId);

add namespace 添加命名空间

using umbraco.NodeFactory;

You can also do 你也可以

Document doc = new Document(nodeId)

This works the same as Node but gets the values straight from the database instead of the XML cache. 这与Node工作方式相同,但直接从数据库而不是XML缓存中获取值。 Use this if you're going to be updating the documents property values. 如果您要更新文档属性值,请使用此选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM