JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://cdnjs.cloudflare.com/ajax/libs/knockout/2.2.1/knockout-min.js"></script>
your PType is: <span data-bind="text: getEnumStringRepresentation('PType',PType())"></span>
<br/>
your ClientType is: <span data-bind="text: getEnumStringRepresentation('ClientType',ClientType())"></span>
JavaScript
var PTypeEnum = {
0: "Undefined",
1: "Low Structure",
2: "Hight Structure"
};
var ClientTypeEnum = {
0: "Undefined",
1: "P Type",
2: "S Type"
};
var itemObj = {
PType: ko.observable(0),
ClientType: ko.observable(2),
property1: ko.observable(''), // put here the other properties if you have more
getEnumStringRepresentation: function (enumType, enumVaue) {
debugger;
switch (enumType) {
case 'PType':
return PTypeEnum[enumVaue];
case 'ClientType':
return ClientTypeEnum[enumVaue];
default:
return "";
}
}
};
ko.applyBindings(itemObj);