durandal/breeze を使用して asp.net mvc ソリューションを開発しています。
Entity Framework Code First によって提供される Enum からリストが取り込まれるドロップダウンがあります。モデルサーバー側は次のとおりです。
public enum EnumCategory
{
Cat1,
Cat2,
Cat3,
Cat4
}
この列挙型を使用する表は次のとおりです。
public class Transport
{
[Key]
public int Id { get; set; }
public EnumCategory Category { get; set; }
...
}
私の質問:列挙型サーバー側のこれらの値を取得して、ドロップダウン クライアント側に入力できるようにする方法を教えてください。次のようにクライアント側で新しいアレイを手動で作成する必要がありますか?
var categories = [
{ id: '' , description: '' },
{ id: 'Cat1', description: 'Category 1' },
{ id: 'Cat2', description: 'Category 2' },
{ id: 'Cat3', description: 'Category 3' },
{ id: 'Cat4', description: 'Category 4' }];
私のビューには、このドロップダウンが次のように表示されます。
<select data-bind="options: $root.categories,
optionsText: 'description',
optionsValue: 'id',
value: category,
validationOptions: { errorElementClass: 'input-validation-error' },
valueUpdate: 'afterkeydown'">
</select>
サーバー側の値のリストが既にあるため、クライアント側の値のリストを再作成する必要があるのは冗長に思えます。
何か案が?
ありがとう。