locked
Meaning of arrayFirst RRS feed

  • Question

  • User-1350042179 posted

    Hi

    I dont know the interpretation of:

       var match = ko.utils.arrayFirst(self.Prop_GridControl.Prop_SelectedItems(), function (item) {
                    return "ESPE0001" != item.IdEstado;
                });
                return match === undefined || match === null;

    In the code:

    self.Trigger_SeleccionGrilla = ko.observable();
        self.Comp_PuedeEliminar = ko.computed(function () {
            self.Trigger_SeleccionGrilla();
            var hasSelection = self.Prop_GridControl.Prop_SelectedItems().length > 0;
            if (hasSelection) {
                var match = ko.utils.arrayFirst(self.Prop_GridControl.Prop_SelectedItems(), function (item) {
                    return "ESPE0001" != item.IdEstado;
                });
                return match === undefined || match === null;
            } else {
                return false;
            }        
        }, self);

    Monday, January 15, 2018 4:08 AM

Answers

  • User1400794712 posted

    Hi neoaguil17,

    According to your code, arrayFirst will execute a function——

    function (item) {
        return "ESPE0001" != item.IdEstado;
    }
    

    —— for each 'item' in self.Prop_GridControl.Prop_SelectedItems() array. Then return the first item, the function evaluation of which is true.

    Then if there is no such an item, return true.

    For more details, please refer to this article.

    Best Regards,

    Daisy

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 16, 2018 7:27 AM

All replies

  • User753101303 posted

    Hi,

    I made a search and it seems to just return the first element that matches a condition (ie here for which "ESPE0001" != item.IdEstado is true).

    I tried to see if you could find this in the doc but according to https://groups.google.com/forum/#!topic/knockoutjs/KpB3SBqg5iI it seems ko.utils is supposed to be for internal use.

    Monday, January 15, 2018 1:09 PM
  • User1400794712 posted

    Hi neoaguil17,

    According to your code, arrayFirst will execute a function——

    function (item) {
        return "ESPE0001" != item.IdEstado;
    }
    

    —— for each 'item' in self.Prop_GridControl.Prop_SelectedItems() array. Then return the first item, the function evaluation of which is true.

    Then if there is no such an item, return true.

    For more details, please refer to this article.

    Best Regards,

    Daisy

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 16, 2018 7:27 AM