# Zelect **Repository Path**: mirrors/Zelect ## Basic Information - **Project Name**: Zelect - **Description**: Zelect 是一个能够创建自定义 ``` ```javascript $('#select-backed-zelect').zelect() ``` ## Asyncronous Paged Setup If the option list is server-backed, infinite or close to it, use `opts.loader`: ```html ``` ```javascript $('#async-backed-zelect').zelect({ initial: 'Third', loader: function(term, page, callback) { callback(['First for page '+page, 'Second', 'Third']) } }) ``` Callback expects an array. Elements in the array can be anything that renderItem can handle. zelect will load the next page of results from `opts.loader` whenever the option list is scrolled to the bottom. It will stop trying to load more once the callback is called with an empty array. ## Subscribing to Changes These events are triggered on the <select>-element:
eventargstriggered when
ready-zelect is ready: first results have loaded and the initial selection has been made
changeevent, itemSelected item changed. 2nd parameter is the item itself.
#### In addition: If the zelect is <select>-backed, `$('select').val()` will return the _value_ of the currently selected option. `$('select').data('zelect-item')` will always return the currently selected _item_. ## Programmatically Changing The Selection `$('select').zelectItem(myNewItemThatIWantToSelectNow, fireChangeEvent)` will do that. Whether a change event fires can be controlled with the `fireChangeEvent` boolean. The default is true. ## Programmatically Refreshing an Externally Updated Item `$('select').refreshZelectItem(myUpdatedItem, function(item) { return item._id })` will replace and rerender the item matching myUpdatedItem._id with the new version. No change events are fired. ## Programmatically Resetting the Zelect `$('select').resetZelect()` will reset the query to an empty string, load the first results and select the first item. A change event will fire. ## Styling zelect comes with **no** base css. Make your own. For inspiration, see an example. ## Initial Selection When first rendered, zelect determines the initially selected item in this order: 1. `opts.initial` if defined 2. `