Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Your solution works fine and I didn't find a better solution. I've just upgraded it little bit, by automatic fill the options, so it is usable to any Enum class.

Here I found how to enumerate Enum type Here I found how to enumerate Enum type

export class SelectEditorObject
{
 private options: KnockoutObservableArray<keyValuePair<number, string>>;
 private selection: KnockoutObservable<number>;
 constructor(e: any, value: number)
 {
 var options = SelectEditorObject.getNamesAndValues(e);
 this.selection = ko.observable<number>(value);
 this.options = ko.observableArray<keyValuePair<number, string>>(options);
 }
 public toString()
 {
 var selected = undefined;
 this.options().forEach((pair) =>
 {
 if (pair.key === this.selection())
 {
 selected = pair.value;
 }
 }, this);
 return selected;
 }
 public getValue()
 {
 return this.selection();
 }
 private static getNames(e: any)
 {
 return Object.keys(e).filter(v => isNaN(parseInt(v, 10)));
 }
 private static getValues(e: any)
 {
 return Object.keys(e).map(v => parseInt(v, 10)).filter(v => !isNaN(v));
 }
 public static getNamesAndValues(e: any): Array<keyValuePair<number, string>>
 {
 return SelectEditorObject.getValues(e).map(v => { return new keyValuePair(v, e[v]) });
 }
}
export class keyValuePair<key_type, value_type>
{
 public key: key_type;
 public value: value_type;
 constructor(key: key_type, value: value_type)
 {
 this.key = key;
 this.value = value;
 }
}

Your solution works fine and I didn't find a better solution. I've just upgraded it little bit, by automatic fill the options, so it is usable to any Enum class.

Here I found how to enumerate Enum type

export class SelectEditorObject
{
 private options: KnockoutObservableArray<keyValuePair<number, string>>;
 private selection: KnockoutObservable<number>;
 constructor(e: any, value: number)
 {
 var options = SelectEditorObject.getNamesAndValues(e);
 this.selection = ko.observable<number>(value);
 this.options = ko.observableArray<keyValuePair<number, string>>(options);
 }
 public toString()
 {
 var selected = undefined;
 this.options().forEach((pair) =>
 {
 if (pair.key === this.selection())
 {
 selected = pair.value;
 }
 }, this);
 return selected;
 }
 public getValue()
 {
 return this.selection();
 }
 private static getNames(e: any)
 {
 return Object.keys(e).filter(v => isNaN(parseInt(v, 10)));
 }
 private static getValues(e: any)
 {
 return Object.keys(e).map(v => parseInt(v, 10)).filter(v => !isNaN(v));
 }
 public static getNamesAndValues(e: any): Array<keyValuePair<number, string>>
 {
 return SelectEditorObject.getValues(e).map(v => { return new keyValuePair(v, e[v]) });
 }
}
export class keyValuePair<key_type, value_type>
{
 public key: key_type;
 public value: value_type;
 constructor(key: key_type, value: value_type)
 {
 this.key = key;
 this.value = value;
 }
}

Your solution works fine and I didn't find a better solution. I've just upgraded it little bit, by automatic fill the options, so it is usable to any Enum class.

Here I found how to enumerate Enum type

export class SelectEditorObject
{
 private options: KnockoutObservableArray<keyValuePair<number, string>>;
 private selection: KnockoutObservable<number>;
 constructor(e: any, value: number)
 {
 var options = SelectEditorObject.getNamesAndValues(e);
 this.selection = ko.observable<number>(value);
 this.options = ko.observableArray<keyValuePair<number, string>>(options);
 }
 public toString()
 {
 var selected = undefined;
 this.options().forEach((pair) =>
 {
 if (pair.key === this.selection())
 {
 selected = pair.value;
 }
 }, this);
 return selected;
 }
 public getValue()
 {
 return this.selection();
 }
 private static getNames(e: any)
 {
 return Object.keys(e).filter(v => isNaN(parseInt(v, 10)));
 }
 private static getValues(e: any)
 {
 return Object.keys(e).map(v => parseInt(v, 10)).filter(v => !isNaN(v));
 }
 public static getNamesAndValues(e: any): Array<keyValuePair<number, string>>
 {
 return SelectEditorObject.getValues(e).map(v => { return new keyValuePair(v, e[v]) });
 }
}
export class keyValuePair<key_type, value_type>
{
 public key: key_type;
 public value: value_type;
 constructor(key: key_type, value: value_type)
 {
 this.key = key;
 this.value = value;
 }
}
edited body
Source Link
BCdotWEB
  • 11.4k
  • 2
  • 28
  • 45

Your solution work'sworks fine and I didn't found anyfind a better solution. I've just upgraded it little bit, by automatic fill the options, so it is usable to any EnumEnum class.

Here iI found how to enumarete Enumenumerate Enum type

export class SelectEditorObject
{
 private options: KnockoutObservableArray<keyValuePair<number, string>>;
 private selection: KnockoutObservable<number>;
 constructor(e: any, value: number)
 {
 var options = SelectEditorObject.getNamesAndValues(e);
 this.selection = ko.observable<number>(value);
 this.options = ko.observableArray<keyValuePair<number, string>>(options);
 }
 public toString()
 {
 var selected = undefined;
 this.options().forEach((pair) =>
 {
 if (pair.key === this.selection())
 {
 selected = pair.value;
 }
 }, this);
 return selected;
 }
 public getValue()
 {
 return this.selection();
 }
 private static getNames(e: any)
 {
 return Object.keys(e).filter(v => isNaN(parseInt(v, 10)));
 }
 private static getValues(e: any)
 {
 return Object.keys(e).map(v => parseInt(v, 10)).filter(v => !isNaN(v));
 }
 public static getNamesAndValues(e: any): Array<keyValuePair<number, string>>
 {
 return SelectEditorObject.getValues(e).map(v => { return new keyValuePair(v, e[v]) });
 }
}
export class keyValuePair<key_type, value_type>
{
 public key: key_type;
 public value: value_type;
 constructor(key: key_type, value: value_type)
 {
 this.key = key;
 this.value = value;
 }
}

Your solution work's fine and I didn't found any better solution. I've just upgraded it little bit, by automatic fill the options, so it is usable to any Enum class.

Here i found how to enumarete Enum type

export class SelectEditorObject
{
 private options: KnockoutObservableArray<keyValuePair<number, string>>;
 private selection: KnockoutObservable<number>;
 constructor(e: any, value: number)
 {
 var options = SelectEditorObject.getNamesAndValues(e);
 this.selection = ko.observable<number>(value);
 this.options = ko.observableArray<keyValuePair<number, string>>(options);
 }
 public toString()
 {
 var selected = undefined;
 this.options().forEach((pair) =>
 {
 if (pair.key === this.selection())
 {
 selected = pair.value;
 }
 }, this);
 return selected;
 }
 public getValue()
 {
 return this.selection();
 }
 private static getNames(e: any)
 {
 return Object.keys(e).filter(v => isNaN(parseInt(v, 10)));
 }
 private static getValues(e: any)
 {
 return Object.keys(e).map(v => parseInt(v, 10)).filter(v => !isNaN(v));
 }
 public static getNamesAndValues(e: any): Array<keyValuePair<number, string>>
 {
 return SelectEditorObject.getValues(e).map(v => { return new keyValuePair(v, e[v]) });
 }
}
export class keyValuePair<key_type, value_type>
{
 public key: key_type;
 public value: value_type;
 constructor(key: key_type, value: value_type)
 {
 this.key = key;
 this.value = value;
 }
}

Your solution works fine and I didn't find a better solution. I've just upgraded it little bit, by automatic fill the options, so it is usable to any Enum class.

Here I found how to enumerate Enum type

export class SelectEditorObject
{
 private options: KnockoutObservableArray<keyValuePair<number, string>>;
 private selection: KnockoutObservable<number>;
 constructor(e: any, value: number)
 {
 var options = SelectEditorObject.getNamesAndValues(e);
 this.selection = ko.observable<number>(value);
 this.options = ko.observableArray<keyValuePair<number, string>>(options);
 }
 public toString()
 {
 var selected = undefined;
 this.options().forEach((pair) =>
 {
 if (pair.key === this.selection())
 {
 selected = pair.value;
 }
 }, this);
 return selected;
 }
 public getValue()
 {
 return this.selection();
 }
 private static getNames(e: any)
 {
 return Object.keys(e).filter(v => isNaN(parseInt(v, 10)));
 }
 private static getValues(e: any)
 {
 return Object.keys(e).map(v => parseInt(v, 10)).filter(v => !isNaN(v));
 }
 public static getNamesAndValues(e: any): Array<keyValuePair<number, string>>
 {
 return SelectEditorObject.getValues(e).map(v => { return new keyValuePair(v, e[v]) });
 }
}
export class keyValuePair<key_type, value_type>
{
 public key: key_type;
 public value: value_type;
 constructor(key: key_type, value: value_type)
 {
 this.key = key;
 this.value = value;
 }
}
Source Link
prespic
  • 111
  • 1

Your solution work's fine and I didn't found any better solution. I've just upgraded it little bit, by automatic fill the options, so it is usable to any Enum class.

Here i found how to enumarete Enum type

export class SelectEditorObject
{
 private options: KnockoutObservableArray<keyValuePair<number, string>>;
 private selection: KnockoutObservable<number>;
 constructor(e: any, value: number)
 {
 var options = SelectEditorObject.getNamesAndValues(e);
 this.selection = ko.observable<number>(value);
 this.options = ko.observableArray<keyValuePair<number, string>>(options);
 }
 public toString()
 {
 var selected = undefined;
 this.options().forEach((pair) =>
 {
 if (pair.key === this.selection())
 {
 selected = pair.value;
 }
 }, this);
 return selected;
 }
 public getValue()
 {
 return this.selection();
 }
 private static getNames(e: any)
 {
 return Object.keys(e).filter(v => isNaN(parseInt(v, 10)));
 }
 private static getValues(e: any)
 {
 return Object.keys(e).map(v => parseInt(v, 10)).filter(v => !isNaN(v));
 }
 public static getNamesAndValues(e: any): Array<keyValuePair<number, string>>
 {
 return SelectEditorObject.getValues(e).map(v => { return new keyValuePair(v, e[v]) });
 }
}
export class keyValuePair<key_type, value_type>
{
 public key: key_type;
 public value: value_type;
 constructor(key: key_type, value: value_type)
 {
 this.key = key;
 this.value = value;
 }
}
lang-js

AltStyle によって変換されたページ (->オリジナル) /