extjs怎么加载js文件 生成左边的树形菜单

JavaScript08

extjs怎么加载js文件 生成左边的树形菜单,第1张

研究一下 extjs的tree树形结果,已经封装的很简单了

Ext.require([

'Ext.tree.*',

'Ext.data.*'

])

Ext.onReady(function() {

var store = Ext.create('Ext.data.TreeStore', {

proxy: {

type: 'ajax',

url: 'get-nodes.php',

extraParams: {

isXml: true

},

reader: {

type: 'xml',

root: 'nodes',

record: 'node'

}

},

sorters: [{

property: 'leaf',

direction: 'ASC'

},{

property: 'text',

direction: 'ASC'

}],

root: {

text: 'Ext JS',

id: 'src',

expanded: true

}

})

// create the Tree

var tree = Ext.create('Ext.tree.Panel', {

store: store,

hideHeaders: true,

rootVisible: true,

viewConfig: {

plugins: [{

ptype: 'treeviewdragdrop'

}]

},

height: 350,

width: 400,

title: 'Directory Listing',

renderTo: 'tree-example',

collapsible: true

})

})

1、首先,需要先创建一个基本可用的 ExtJS 模板, 这个很简单, 如下所示:

<!DOCTYPE html>

<html>

<head>

<title></title>

<link rel="stylesheet" type="text/css" href="http://localhost/ext-4/resources/css/ext-all.css" />

<script type="text/javascript" src="http://localhost/ext-4/ext-debug.js"></script>

</head>

<body>

</body>

</html>

2、需要引用的脚本是 ExtJS 根目录下的 ext-debug.js , 不是 ext-all-debug.js, 这个文件非常小, 只有几百K , 当让这个只是最基本的 ExtJS 组件, 不包括任何的界面功能。

3、配置 Ext.Loader 启用动态加载;

4、ExtJS 中的动态加载是由 Ext.Loader 来完成的, 默认不启用动态加载, 所以接下来需要做的事配置 Ext.Loader 启用动态加载, 在上面模板的 body 标签内添加如下代码:

<script type="text/javascript">

Ext.onReady(function() {

Ext.Loader.setConfig({

enabled: true,

disableCaching: false,

paths: {

Ext : '/ext-4/src'

}

})

})

</script>

注意:上面的代码启用了动态加载, 禁用了浏览器缓存, 以及指定了 ExtJS 的所部署的路径。