Skip to content
This repository was archived by the owner on Aug 16, 2021. It is now read-only.
This repository was archived by the owner on Aug 16, 2021. It is now read-only.

error when multiple is activated and all entries do not have children #222

@watsab

Description

@watsab

Hi!

I'm facing an issue which may be also a needed improvement.
Here's the situation:
I have a list of results (from an Ajax query) that looks as following:

[
  {
    children: [
      {
        id: 'child',
        text: 'My child',
      },
      {
        id: 'child2',
        text: 'My second child',
      },
    ],
    id: 'parent',
    text: 'Parent',
  },
 {
    id: 'other',
    text: 'Other',
  }
]

The issue I'm facing is that when the selectivity plugin is intanciated with the multiple option set to true, the filterResults method raises the exception 'TypeError: Cannot read property 'some' of undefined'. As a matter of fact, filterResults checks if any of its results has children (line 124) and this causes the trouble since the filterResults is called on the item's children even if it does not have any (line 132).
I don't know if it makes sense, but would it be possible to modify the filterResults method so there is a check that children actually exists ?
Something like this:

filterResults: function(results) {
 results = results.map(function(item) {
   const result = {
     id: item.id,
     text: item.text,
   };
   if(!!item.children) {
       result['children'] = this.filterResults(item.children);
   }
   return result;
 }, this);

 return results.filter(function(item) {
   return !Selectivity.findById(this._data, item.id);
 }, this);
},

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions