Package: | Ext |
Class: | View |
Extends: | Observable |
Subclasses: | JsonView |
Defined In: | View.js |
var store = new Ext.data.Store(...);
var view = new Ext.View("my-element",
'<div id="{0}">{2} - {1}</div>', // 自动创建模板
{
singleSelect: true,
selectedClass: "ydataview-selected",
store: store
});
// 是否侦听节点的单击事件?
view.on("click", function(vw, index, node, e){
alert('Node "' + node.id + '" at index: ' + index + " was clicked.");
});
// 加载XML数据
dataModel.load("foobar.xml");
关于创建 JSON/UpdateManager view 的例子,可见 Ext.JsonView
。属性 | 定义对象 | |
---|---|---|
selectedClass : Ext.DomHelper.Template | View | |
显示节点已选取的CSS样式类 | ||
tpl : Ext.DomHelper.Template | View | |
渲染模板对象或是创建模板的字符串 |
方法 | 定义对象 | |
---|---|---|
View
(String/HTMLElement/Element container , String/DomHelper.Template tpl , Object config ) |
View | |
创建一个 View 对象 | ||
addEvents
(Object object ) : void |
Observable | |
将对象中没有的事件从给出的对象中复制过来。 | ||
addListener
(String eventName , Function handler , [Object scope ], [Object options ]) : void |
Observable | |
为该组件加入事件处理器函数 | ||
clearSelections
([Boolean suppressEvent ]) : void |
View | |
Clear all selections | ||
findItemFromChild
(HTMLElement node ) : HTMLElement |
View | |
Returns the template node the passed child belongs to or null if it doesn't belong to one. | ||
fireEvent
(String eventName , Object... args ) : Boolean |
Observable | |
触发指定的事件, 并将参数传入(至少要有事件名称)。 | ||
getEl () : Ext.Element | View | |
Returns the element this view is bound to. | ||
getNode
(HTMLElement/String/Number nodeInfo ) : HTMLElement |
View | |
Gets a template node. | ||
getNodes
(Number startIndex , Number endIndex ) : Array |
View | |
Gets a range template nodes. | ||
getSelectedIndexes () : Array | View | |
Get the indexes of the selected nodes. | ||
getSelectedNodes () : Array | View | |
Get the currently selected nodes. | ||
getSelectionCount () : Number | View | |
Get the number of selected nodes. | ||
hasListener
(String eventName ) : Boolean |
Observable | |
检查该对象是否拥有指定事件的侦听器 | ||
indexOf
(HTMLElement/String/Number nodeInfo ) : Number |
View | |
Finds the index of the passed node | ||
isSelected
(HTMLElement/Number node ) : Boolean |
View | |
Returns true if the passed node is selected | ||
on
(String eventName , Function handler , [Object options ]) : void |
Observable | |
为该组件加入事件处理器函数, addListener 的简写方式 | ||
prepareData
(Array/Object data ) : void |
View | |
Function to override to reformat the data that is sent to the template for each node. | ||
purgeListeners () : void | Observable | |
从对象身上移除所有的侦听器 | ||
refresh () : void | View | |
Refreshes the view. | ||
refreshNode
(Number index ) : void |
View | |
Refresh an individual node. | ||
removeListener
(String eventName , Function handler , [Object scope ]) : void |
Observable | |
移除侦听器 | ||
select
(Array/HTMLElement/String/Number nodeInfo , [Boolean keepExisting ], [Boolean suppressEvent ]) : void |
View | |
Selects nodes. | ||
setStore
(Store store ) : void |
View | |
Changes the data store this view uses and refresh the view. | ||
un
(String eventName , Function handler , [Object scope ]) : void |
Observable | |
移除侦听器, removeListener 的简写方式 |
事件 | 定义对象 | |
---|---|---|
beforeclick
: (Ext.View this , Number index , HTMLElement node , Ext.EventObject e ) |
View | |
Fires before a click is processed. Returns false to cancel the default action. | ||
beforeselect
: (Ext.View this , HTMLElement node , Array selections ) |
View | |
Fires before a selection is made. If any handlers return false, the selection is cancelled. | ||
click
: (Ext.View this , Number index , HTMLElement node , Ext.EventObject e ) |
View | |
Fires when a template node is clicked. | ||
contextmenu
: (Ext.View this , Number index , HTMLElement node , Ext.EventObject e ) |
View | |
Fires when a template node is right clicked. | ||
dblclick
: (Ext.View this , Number index , HTMLElement node , Ext.EventObject e ) |
View | |
Fires when a template node is double clicked. | ||
selectionchange
: (Ext.View this , Array selections ) |
View | |
Fires when the selected nodes change. |
public Ext.DomHelper.Template selectedClass
public Ext.DomHelper.Template tpl
public function View(String/HTMLElement/Element container
, String/DomHelper.Template tpl
, Object config
)
container
: String/HTMLElement/Element
tpl
: String/DomHelper.Template
config
: Object
public function addEvents(Object object
)
object
: Object
void
public function addListener(String eventName
, Function handler
, [Object scope
], [Object options
])
eventName
: String
handler
: Function
scope
: Object
options
: Object
组合选项
使用选项参数可以组合不同类型的监听器:
下面是一个标准的、延迟执行的、一次性的监听器,将会自动停止事件并传递一个自定义的参数(forumId)
el.on('click', this.onClick, this, { single: true, delay: 100, stopEvent : true, forumId: 4 });
这个方法也允许传递的单个参数是一个包含多个指定处理函数的设置对象。
一次调用多个处理函数
代码:
el.on({ 'click' : { fn: this.onClick scope: this, delay: 100 }, 'mouseover' : { fn: this.onMouseOver scope: this }, 'mouseout' : { fn: this.onMouseOut scope: this } });
或者简写为:
代码:
el.on({ 'click' : this.onClick, 'mouseover' : this.onMouseOver, 'mouseout' : this.onMouseOut scope: this });
void
public function clearSelections([Boolean suppressEvent
])
suppressEvent
: Boolean
void
public function findItemFromChild(HTMLElement node
)
node
: HTMLElement
HTMLElement
public function fireEvent(String eventName
, Object... args
)
eventName
: String
args
: Object...
Boolean
public function getEl()
Ext.Element
public function getNode(HTMLElement/String/Number nodeInfo
)
nodeInfo
: HTMLElement/String/Number
HTMLElement
public function getNodes(Number startIndex
, Number endIndex
)
startIndex
: Number
endIndex
: Number
Array
public function getSelectedIndexes()
Array
public function getSelectedNodes()
Array
public function getSelectionCount()
Number
public function hasListener(String eventName
)
eventName
: String
Boolean
public function indexOf(HTMLElement/String/Number nodeInfo
)
nodeInfo
: HTMLElement/String/Number
Number
public function isSelected(HTMLElement/Number node
)
node
: HTMLElement/Number
Boolean
public function on(String eventName
, Function handler
, [Object options
])
eventName
: String
handler
: Function
options
: Object
void
public function prepareData(Array/Object data
)
data
: Array/Object
void
public function purgeListeners()
void
public function refresh()
void
public function refreshNode(Number index
)
index
: Number
void
public function removeListener(String eventName
, Function handler
, [Object scope
])
eventName
: String
handler
: Function
scope
: Object
void
public function select(Array/HTMLElement/String/Number nodeInfo
, [Boolean keepExisting
], [Boolean suppressEvent
])
nodeInfo
: Array/HTMLElement/String/Number
keepExisting
: Boolean
suppressEvent
: Boolean
void
public function setStore(Store store
)
store
: Store
void
public function un(String eventName
, Function handler
, [Object scope
])
eventName
: String
handler
: Function
scope
: Object
void
public event beforeclick
this
: Ext.View
index
: Number
node
: HTMLElement
e
: Ext.EventObject
public event beforeselect
this
: Ext.View
node
: HTMLElement
selections
: Array
public event click
this
: Ext.View
index
: Number
node
: HTMLElement
e
: Ext.EventObject
public event contextmenu
this
: Ext.View
index
: Number
node
: HTMLElement
e
: Ext.EventObject
public event dblclick
this
: Ext.View
index
: Number
node
: HTMLElement
e
: Ext.EventObject
public event selectionchange
this
: Ext.View
selections
: Array