javascript - how to display a modal on a selected item in knockout -
i have list of services getting api, values id, name , needauthorization, , when service need authorization, want display modal box enter authorization code. i'm trying this:
selectedservice.subscribe(function (newvalue) { if (services().needauthorization == 1 && selectedservice == services().id) { $('#preauthorizationmodal').modal('show'); } });
but it's not working me. i'm new knockout , lil bit of appreciated. in advance
presenting , dismissing knockout can done 'if' or 'with' binding. create "modallayer" responsible showing modals. communicate layer using signals/events/subscriptions example.
the html modallayer like.
<!-- ko with: modalviewmodel --> <div data-bind="text: title"></div> <div data-bind="text: body"></div> <div data-bind="foreach: buttons"> ... </div> <!-- /ko -->
or using components...
<!-- ko if: componentname --> <div data-bind="component: { name: componentname, params: componentparams }"></div> <!-- /ko -->