0

I am a bit confused. I have the following code in the directive:

NavTabsDirective.prototype.addPane = function (pane) {
        if (!_.isObject(pane) || "Pane" !== pane.constructor.name) {
            throw new TypeError("pane must be an instance of Pane");
        }

        if (_.isUndefined(this.FirstPane)) {
            this.FirstPane = pane;
        }
        
        this.Panes[pane.name] = pane;
    };

when I look in the debugger at the this.Panes array, I see something like:

this.Panes[name1] = paneObject -- with properties
this.Panes[name2] = paneObject -- with its properties

I want to understand how to search this array. Say, this is my code:

let invalid = (_.findIndex(this.Panes, { 'isValid': false })>=0);

which I commented out as it could not find a pane where isValid is false although I can see such pane in that array.

So, my confusion comes from the fact that the Panes array object has names to access each pane object and so I don't know how to properly search it. How would I check for invalid among the panes?

3 Answers 3

1

Unless pane.name is a number the panes in this.panes is not an array, it's an object, you can use it's keys and reduce it to a value:

const result = Object.keys(this.Panes).reduce(
  (all,key)=>all && this.Panes[key].isValid,
  true
)
Sign up to request clarification or add additional context in comments.

1 Comment

I was able to come up with a similar solution last night, see my answer to myself. I have to slightly adjust it and pass back the array of invalid tabs and not just the status, but the idea was to use for loop.
0

Figured out a solution after checking few threads here:

for (let pane in this.Panes) {
                if (this.Panes[pane].isValid === false) {
                    invalid = true;
                    break;
                }
            }

It works nicely.

Comments

0

var Panes = ["Hello","World"];
var PanesLength = Panes.length;
for (var i = 0; i < PanesLength; i++) {
    if(Panes[i] == "Hello"){
      alert(Panes[i]);
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.