I have a job description page, and I am adding values to it programmatically. One of the fields is "Office Locations", with a data type of Treelist. How can I add values to the Treelist so that I can set the office location?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Sitecore Treelist
stores the ids of selected items in a pipeline separated form.
If you want to set the value of Treelist
programmatically you need to set it to a string which looks like:
{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}|{EA015A5F-C41B-4510-B538-438EF204F5E2}
where {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}
, {EA015A5F-C41B-4510-B538-438EF204F5E2}
and possibly more of the string parts separated with |
characters are ids of chosen pages.
using (new EditContext(jobItem))
{
jobItem["OfficeLocations"] = "{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}|{EA015A5F-C41B-4510-B538-438EF204F5E2}";
}