mobile-list
v0.1.0
Published
full featured list build for mobile first
Readme
Mobile-list
Full featured list build for mobile first, while design ignorant.
Features
- Optional iscroll, pull-to-refresh and more
- Reactive support by reactive-lite
- Sort and filter data on remote/local mode
- Event delegate for better performance
Install
npm i mobile-listUsage
var List = require('mobile-list')
var template = require('./template.html')
var list = new List(template, window, {
selector: 'ul.mylist'
})
api.loadUsers(function(err, arr) {
list.setData(arr)
})Events
sortemit with params when remote sort needed (includingsortFieldsortDirection)filteremit with params when remote filter needed (includingfilterFieldfilterValud)pageemit with params when remote paging needed (includingcurpage,perpage)removeemit just before this component removed
API
List(template, scrollable, [option])
templatetemplate string or element for repeat renderscrollablethe scrollable elementoptionoptional option for list-renderoption.perpagemax page count perpage for paging, works with pageroption.selectorselector for parentNode of repeat template, defaultuloption.delegatedelegate object for reactiveoption.bindingsbindings object for reactiveoption.filtersfilters object for reactiveoption.modelmodel class used for generate modeloption.emptyString or Element rendered in parentNode when internal data list is emptyoption.limitthe limit number for render whensetData()(default no limit)option.moreCountworks withoption.limitit limit count of items to render with.more(n)method when last item visible on scroll, default 10option.autoHeightset the height of parentNode even if data not rendered (need limit to work, items should have same height)
List inherits all methods from list-render, the extra methods are shown below
.iscroll([option])
Use iscroll for smooth scrolling, set option.handlebar to true if your want handlebar to show
.pullToRefresh([option], callback)
optionsis pull-to-refresh options, which may have texts or/and templatecallbackshould return a promise which resolve an array of data(or reject error) for rendercallbackis called with additional parampullTimestampwhich contains time stamp of latest succeed pull.
.useMore(callback)
Use more for loading more data,
callback should return promise which resolve an array of data(or reject error) for render
.bind(type, selector, handler)
Delegate event type to selector with handler,
handler is called with event and a reactive model
.local()
Make list works on local model, which means sort, filter and paging only happens locally
.sort(field, dir, [method])
Sort the data by field, direction or method, when it's remote mode(default mode), emit event only
.filter(field, val|function)
Filter the data by field, val or function, when it's remote mode(default mode), emit event only
.refresh()
Let pull-to-refresh to refresh more data
.setTotal(n)
Set total data count for paging, can not used for local mode
.remove()
Remove all rendered repeat elements and unbind all events
