ListView
View for the collection of items.
Example:
class ListItemView extends View {
html(data) {
return `<li>${data.title}</li>`;
}
}
let instanceView = new ListView(Node, ListItemView,
{
data: [
{ title: 'foo' },
{ ttile: 'bar' }
]
});
Constructor Summary
Public Constructor | ||
public |
|
Method Summary
Public Methods | ||
public |
Add an item to list |
|
public |
insertItem(item: object, index: number): * Insert an item to list at index |
|
public |
itemViewClass(item: object): Class<View> If you dynamically change creating item view according to the item, override this method. |
|
public |
removeItem(item: object, index: number) Remove item from list |
|
public |
removeItemByView(view: view) Remove item with view |
|
public |
updateItem(item: object, index: number) Update an item at index |
Protected Methods | ||
protected |
addItemEl(listEl: Element, itemEl: Element) If you change adding item effect, override this method. |
|
protected |
insertItemEl(listEl: Element, newEl: Element, nextEl: Element) If you change inserting item effect, override this method. |
|
protected |
removeItemEl(listEl: Element, itemEl: Element) If you change removing item effect, override this method. |
Private Methods | ||
private |
|
|
private |
_childElAt(index: number): Element Return child element at position. |
|
private |
_createViewByItem(item: *): * |
|
private |
_privates(): * |
|
private |
_removeItemByEl(el: element) Remove item from list by element |
|
private |
|
Inherited Summary
From class Core | ||
public |
Add handler or listener for saying message |
|
public |
Cast a message to the listeners |
|
public |
unescapeHtml(escaped: String): String Unescape HTML |
|
public |
unlistened(name: string, -: Function) Remove handler or listener |
|
private |
_callR(args: *, target: *, method: *, methodOwner: *) |
|
private |
_isFn(f: *): * |
|
private |
_isStr(v: *): * |
|
private |
_listened(name: *, handler: *) |
|
private |
_privates(): {"_F_obs": *} Return non-enumerable attribute definitions. |
|
private |
_say(targetName: *, name: *, ctx: *) |
From class View | ||
public get |
data: * data to elements text or value, innerHTML of elements |
|
public set |
|
|
public |
contentEl: * |
|
public |
el: * Root element |
|
public |
parent: * |
|
public |
views: {} Subview children of the view |
|
private |
_data: * |
|
public |
appendEl(el: Element) Append child element |
|
public |
Cast a message to all children of view |
|
public |
For implement after loading completed |
|
public |
destroy() Destroy all chidren, unload, and destroy binder, teardown events |
|
public |
findEl(id: *): Element Find an element that has specified data-id else call getElementById |
|
public |
Fire event |
|
public |
Ssetting listener of events. |
|
public |
For implement creating subviews and setting listener of events. |
|
public |
prepareData(defaults: object): object | Item Prepare data |
|
public |
Set child view as name after load |
|
public |
unload() For implement unloading subviews |
|
public |
Called when the binding data is updated. |
|
private |
|
|
private |
|
|
private |
_build(root: *, props: *) _loaded resolve after all done |
|
private |
_buildFromHtml(data: *): * |
|
private |
_firstEl(el: *): * |
|
private |
|
|
private |
_parseEvts(evts: *, emap: *) |
|
private |
_privates(): * |
|
private |
Set data to subviews or elements in the view. |
|
private |
Bind targets with event handler set. |
|
private |
_setFieldValue(name: *, val: *): boolean |
|
private |
_setRootNode(root: *, parent: *, data: *) Set root node element to this.el |
|
private |
_setVal(el: *, val: *) |
|
private |
_setupProps(props: *): * |
|
private |
|
|
private |
Bind target event with handler. |
|
private |
|
Public Constructors
Public Methods
public addItem(item: object): * source
Add an item to list
Params:
Name | Type | Attribute | Description |
item | object | an item |
Return:
* |
public itemViewClass(item: object): Class<View> source
If you dynamically change creating item view according to the item, override this method.
Params:
Name | Type | Attribute | Description |
item | object | an item |
public removeItemByView(view: view) source
Remove item with view
Params:
Name | Type | Attribute | Description |
view | view | an view of removing item |
Protected Methods
protected addItemEl(listEl: Element, itemEl: Element) source
If you change adding item effect, override this method.
Params:
Name | Type | Attribute | Description |
listEl | Element | parent element for List |
|
itemEl | Element | added element |
protected insertItemEl(listEl: Element, newEl: Element, nextEl: Element) source
If you change inserting item effect, override this method.
Params:
Name | Type | Attribute | Description |
listEl | Element | parent element for List |
|
newEl | Element | an element for new item for List |
|
nextEl | Element | next element will be next one for newEl |
protected removeItemEl(listEl: Element, itemEl: Element) source
If you change removing item effect, override this method.
Params:
Name | Type | Attribute | Description |
listEl | Element | parent element for List |
|
itemEl | Element | removed element |
Private Methods
private _childElAt(index: number): Element source
Return child element at position.
Params:
Name | Type | Attribute | Description |
index | number | item position. |
Return:
Element | target element |
private _privates(): * source
Return non-enumerable attribute definitions.
Override:
View#_privatesReturn:
* |
private _removeItemByEl(el: element) source
Remove item from list by element
Params:
Name | Type | Attribute | Description |
el | element | removed element |
private _setDataToUI() source
Set data to subviews or elements in the view.