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;
}
}
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;
}
}
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;
}
}