ListView renders a container with list items inside

Example Usage

<div class='search-results'></div>
// Pull in the library
const UI = require('jibe-juice');

// Instantiate a component, pass the selector of the container to insert component into and the opts
const results = new UI.ListView('.search-results', {
  fetch: function(cb) {
    const results = [];
    // go do some stuff to get new results...
    cb(results);
  },
  listItemOpts: {
    attrs: {
      foo: 'bar',
      baz: 'foobar',
      class: 'testClass'
    }
  },

  results: [1, 2, 3, 4, 5] // initial results to show
});

// Subscribe to fire this function whenever a list item is selected
results.subscribe(function(selection) {
  console.log('list item selected', selection);
});

// Render the DOM for the ListView component
results.render();

params

NameTypeDefaultDescription
elstringundefinedA string of the selector for the element to put the component in
optsobject{}A catch all for various options. See the opts table below for options specific to this component.

opts

NameTypeDefaultDescription
fetchfunctionUtils.noopA function to fetch and populate new results data
listItemOptsobject{}An object containing options specifically for each item in listView (See table below for full list of options)

opts.listItemOpts

NameTypeDefaultDescription
attrsobjectundefinedA list of CSS attributes to put on each ListItem
disableClickHandlersbooleanundefinedIf true, disable the click handlers on the list items
renderItemfunctionundefinedDetermines how each listElement will be displayed in DOM
results*[]undefinedAn array of results to prefill the component with data
stopPropagationbooleanundefinedPrevents the click handler from bubbling the event upwards