Skip to content

Conversation

@jakeboone02
Copy link

Pass the items array element as second parameter to generatorFn. This way items can be an array of anything (Backbone.Models, jQuery collections, etc.), and generatorFn can handle it however it wants.

Example:

var i, bigList = [];
for (i = 0; i < 10000; i++) {
  bigList.push({name: "Test Item " + i, desc: "I'm a description"});
}

var list = new VirtualList({
  h: window.innerHeight,
  itemHeight: 30,
  items: bigList,
  generatorFn: function(idx, row) {
    return $("<div>", {text: row.name + " -|- " + row.desc, css: {height: "30px"}})[0];
  }
});

Pass the items array element as second parameter to generatorFn.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.items does not necessary exist here, and if it doesn't, trying to access an element in it would crash.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I see. As long as generatorFn had access to items at runtime, it could use the i argument passed to it to find items[i]. A bit constraining but probably not a showstopper in most cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants