/**
* This example shows basic drag and drop node moving in a tree. In this implementation
* there are no restrictions and anything can be dropped anywhere except appending to nodes
* marked "leaf" (the files).
* 这个例子展示了树节点的基本拖拽功能。只有是leaf属性的节点才能被拖拽。
* In order to demonstrate drag and drop insertion points, sorting is not enabled.
* 为了展示拖拽插入点,排序这里是禁用的
* The data for this tree is asynchronously loaded through a TreeStore and AjaxProxy.
* 树节点数据同步加载于treestore和ajaxproxy
*/
Ext.define('KitchenSink.view.tree.Reorder', {
extend: 'Ext.tree.Panel',
requires: [
'Ext.tree.*',
'Ext.data.*'
],
xtype: 'tree-reorder',
height: 400,
width: 350,
title: 'Files',
useArrows: true,
initComponent: function() {
Ext.apply(this, {
store: new Ext.data.TreeStore({
proxy: {
type: 'ajax',
url: '/tree/get-nodes.php'
},
root: {
text: 'Ext JS',
id: 'src',
expanded: true
},
//folderSort true,在store中,自动前置一个叶子节点的排序
folderSort: true,
sorters: [{
property: 'text',
direction: 'ASC'
}]
}),
viewConfig: {
plugins: {
//treeviewdragdrop插件 提供TreeView的拖动(和/或者)删除功能
ptype: 'treeviewdragdrop',
containerScroll: true
}
},
tbar: [{
text: 'Expand All',
scope: this,
handler: this.onExpandAllClick
}, {
text: 'Collapse All',
scope: this,
handler: this.onCollapseAllClick
}]
});
this.callParent();
},
onExpandAllClick: function(){
var me = this,
//这里的down()括号里为什么是toolbar请看下面
toolbar = me.down('toolbar');
me.getEl().mask('Expanding tree...');
toolbar.disable();
this.expandAll(function() {
me.getEl().unmask();
toolbar.enable();
});
},
onCollapseAllClick: function(){
var toolbar = this.down('toolbar');
toolbar.disable();
this.collapseAll(function() {
toolbar.enable();
});
}
});
Ext.apply
(下面的内容来自于博客园Chance_yin 地址:http://www.cnblogs.com/yin-jingyu/archive/2011/07/30/2122176.html)
Ext中,apply和applyIf方法都是用于实现把一个对象中的属性应用于另一个对象中,相当于属性拷贝。不同的是apply将会覆盖目标对象中的属性,而applyIf只拷贝目标对象中没有而源对象中有的属性。
apply的方法:apply(Object obj,Object config,Object defaults):Object
Object obj:要拷贝的目标对象
Object config:拷贝的源对象
Object defaults:可选,表示给目标对象提供一个默认值
可以简单的理解成把第二个参数和第三个参数(如果有)的属性拷贝给第一个参数的属性。
var b1={ p1:"p1 value", p2:"p2 value", f1:function(){alert(this.p2)}};
var b2=new Object();
b2.p2="b2 value";
Ext.apply(b2,b1);b2.f1();
上面的代码中,Ext.apply(b2,b1)这个语句是把b1的属性拷贝给了b2对象中的属性,因此调用b2的f1方法可以弹出”p2 value”的提示信息。尽管b2对象已经包含了p2的属性值,但拷贝后该属性值会被覆盖。可以在调用apply方法时,在第三个参数中指定拷贝属性的默认值。比如下面的代码:
Ext.apply(b2,b1,{p3:"p3 value"});
alert(b2.p3);
这样会是的b2中包含一个p3的属性,值为“p3 value”
applyIf方法的功能和apply一样,只是不会拷贝那些在目标及源对象都存在的属性。比如前面演示将apply改为applyIf,如下:
Ext.applyIf(b2,b1);b2.f1();
由于b2中已经存在p2属性,因此,b2.f1()方法中引用this.p2的时候,得到的是“b2 value”,而不是b1中定义的“p2 value”
tbar: [
{ xtype: 'button', text: 'Button 1' }
]
等价于
dockedItems: [{
xtype: 'toolbar',
dock: 'top',
items: [
{ xtype: 'button', text: 'Button 1' }
]
}]