更新时间:2023-02-11 19:56:01
Droplist
类似于Droplink
字段类型,因为它们都是下拉列表。Droplist
将只存储项目的名称(因此它没有指向该项目的链接),而Droplink
存储项目的ID。这意味着,如果您重命名选项或将其移动到内容树中的其他位置,Droplist
将不会更新(可能导致链接断开),Droplink将更新。
您可以通过将模板中的Datasource
字段设置为某个值来向Droplist
添加值(例如,/sitecore/content/Home/CSS/
如果您希望将CSS类名存储在该位置)。
您可以使用如下代码访问Droplist
:
Item item = Sitecore.Context.Item;
string css = item["FieldName"]; // Also possible is item.Fields["Fieldname"].Value;
ADroplink
可以这样访问:
string dropDownItemId = item["Fieldname"]; // Or, again, item.Fields["Fieldname"].Value; if you prefer
var cssItem = Sitecore.Context.Database.GetItem(dropDownItemId); // And now you can
// access any fields in this item.
编辑 A good article going into some more detail in the differences between Droplink and Droplist