javascript - KnockoutJS : Create binding handler to change value to enum -
i have knockout custom binding takes value , returns enum. user readability. problem when passing in parameter binding, comes blank. i've tried passing in parameter observable, ex: purchaseorderstatus[status()].
the view:
<td style="vertical-align: top"> <label>status</label><br /> <span data-bind="text: purchaseorderstatus[status]"></span> </td>
the javascript :
purchaseorderstatus = function() { }; purchaseorderstatus.prototype = { closed: 67, deleted: 68, finalized: 70, open: 79} purchaseorderstatus.registerenum('purchaseorderstatus', false);
the way should work if value 70, user sees finalized.
how this.
function model() { var self = this; this.purchaseorderstatus = ko.observable({ '67': 'closed', '68': 'deleted', '70': 'finalized', '79': 'open' }); this.status = ko.observable('68'); } var mymodel = new model(); $(document).ready(function() { ko.applybindings(mymodel); });
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.2/knockout-min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <span data-bind="text: purchaseorderstatus()[status()]"></span>
Comments
Post a Comment