Passing values to ko.computed in Knockout JS



  • 2 Answer(s)

        Every firm must have  a list of clients ,But the user should   use a regular function and pass it the firm :

    self.getClientsForFirm = function (firm) {
        return ko.utils.arrayFilter(self.Clients(), function (item) {
            var fId = item.FirmId();
            return (fId === firm.Id());
        });
    });
    

        Then in html, $data is the present model, in this case the firm:

    <div data-bind="foreach: $root.getClientsForFirm($data)">
    
    Answered on December 19, 2018.
    Add Comment

        Knockout is not permit the user to transfer anything to a computed function. Rather than  just use a regular function there if user wish this .

        The alternate choice  is to have the data already in the dataset on which the user done their 1st foreach.

        This way, The $parent.getClients cannot be used , But this is more like $data.clients.

    Answered on December 19, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.