私はdroptreeというLocationという名前のフィールドを持つテンプレートBrochuresComponentを持っています。 sitecoreテンプレートのフィールドのソースを使用すると、ユーザーはこのドロップダウンオプションに国のアイテムまたは大陸のアイテムを追加できるようになります。私はガラスにオプションの国のアイテムをICountryのガラスアイテムに、大陸のアイテムをIcontinentのガラスアイテムにマッピングしたい。Sitecore Glass Mapper Infer Type Droptree異なるテンプレート項目のフィールド
しかし、ユーザーがドロップダウンでオプションを選択すると、glassItem値の1つが塗りつぶされ、他の評価エラーがあるためモデルにエラーが発生します。以下は私のコードスニペットです。
次のように私のガラスインタフェースになります。次のように
using Collette.Library.GlassItems.Objects.Taxonomy.Locations;
using Collette.Library.GlassItemsConstants.Objects.Page_Components.Destination_Page_Components;
using Glass.Mapper.Sc.Configuration;
using Glass.Mapper.Sc.Configuration.Attributes;
namespace Collette.Library.GlassItems.Objects.Page_Components.Destination_Page_Components
{
[SitecoreType(TemplateId = BrochureComponentsConstants.TemplateIdString, AutoMap = true)]
public interface IBrochuresComponent: IGlassItemEx
{
//Brochures Data Section
[SitecoreField(FieldType = SitecoreFieldType.DropTree, FieldId = BrochureComponentsConstants.LocationItemFieldId, Setting = SitecoreFieldSettings.InferType)]
ICountry Country { get; set; }
[SitecoreField(FieldType = SitecoreFieldType.DropTree, FieldId = BrochureComponentsConstants.LocationItemFieldId, Setting = SitecoreFieldSettings.InferType)]
IContinent Continent { get; set; }
}
}
私のモデルはルックス:
var sitecoreContext = new SitecoreContext();
BrochuresComponentItem = sitecoreContext.Cast<IBrochuresComponent>(DisplayItem);
//IF we specified a continent in dropdown it works fine since that is the first condition so it does not go to else,
//but if we specify a country in the dropdown it breaks at the if condition below stating that templateid is empty string since nothing was evaluated.
空の文字列が許可されていません。 パラメータ名:フィールド名
if (BrochuresComponentItem.Continent != null && BrochuresComponentItem.Continent.TemplateId.Equals(ContinentConstants.TemplateId))
{
SetBrochures(BrochuresComponentItem.Continent);
}
else if (BrochuresComponentItem.Country != null && BrochuresComponentItem.Country.TemplateId.Equals(CountryConstants.TemplateId))
{
SetBrochures(BrochuresComponentItem.Country);
}
また、上記の例ではjammykamが明示的に指定したように、これが動作するためにも 'TemplateId'を指定する必要があります。 –
'IBrochuresComponent'を含むアセンブリとは異なるアセンブリの' ILocationBase'インタフェースを定義する際に注意すべき点はありますか? –
@MatthewDresser:なぜそれが問題になるのかわかりません。自分で試したことはありませんが、プロジェクトのアセンブリへの参照を追加する必要があります。 – jammykam