flaviusmatis / flaviusmatis/simplePagination.js
Cannot set property 'items' of null
- Dominant language
- JavaScript
- Stars
- 777
- Forks
- 397
- PR merge metrics
- No merged PRs in 30d
Description
This error gave me a big headache `$('#paginator').pagination('updateItems', numVideos)`. It's supposed to call this function below. Turns out o is null.
```
updateItems: function (newItems) {
var o = this.data('pagination');
o.items = newItems;
o.pages = Math.ceil(o.items / o.itemsOnPage) ? Math.ceil(o.items / o.itemsOnPage) : 1;
this.data('pagination', o);
methods._draw.call(this);
},
```
After much investigation, I realize that the `init` method is called after updateItems, and that's why o, which is the options object, is null. I did a setTimeout on calling `$('#paginator').pagination('updateItems', numVideos)` and it seems to prevent the error. I'm not sure why this happens though.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by tracing the pagination plugin's init and updateItems entry points, especially the shown call to $('#paginator').pagination('updateItems', numVideos). Reproduce the call without setTimeout and inspect when the pagination data is created. Done means updateItems no longer receives a null pagination object during normal initialization, with the existing behavior preserved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, jquery
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100