1.列出要實現的樣式:

2.實現的代碼:
分三大部分:
1):頁面主體部分:mian.vm
<html>
<head>
<title>Ks UI</title>
#parse("ui:include")
<style>
body{padding:0;margin:0}
</style>
<script>
$(document).ready(function(){
var tabs_content = $("#content");
tabs_content.tabs({
border:false,
fit:true
});
//添加tab頁面
function addTabs(tab){
tabs_content.tabs("add",{
title:tab.text,
closable:true,
content : '<iframe frameborder="0" scrolling="auto" width="100%" height="100%" src="${path}'+tab.url+'"></iframe>'
});
}
$("#tree_menu").tree({
onClick: function(node){
console.log(node);
if(!tabs_content.tabs('exists',node.text)){
if(node.url){
addTabs(node);
}
}else{
tabs_content.tabs("select",node.text);
}
}
});
//添加歡迎頁面
addTabs({
text:'歡迎使用Ks UI',
url:'/cn/com/ksplatform/ui/demo/main/views/fcomponents/welcome.vm'
});
});
</script>
</head>
<body class="easyui-layout">
<div data-options="region:'north'" style="height:70px"></div>
<div data-options="region:'west',split:true" title="菜單" style="width:240px;">
<ul class="easyui-tree" id="tree_menu" data-options="url:'$path/ui/resource/demo/data/tree.json',method:'get',animate:true"></ul>
</div>
<div data-options="region:'center'">
<div class="easyui-tabs" id="content" >
</div>
</div>
</body>
</html>
說明:這部分代碼負責完成效果頁面的整體框架和效果頁面center上面的tabs,重點看tabs是如何實現的(代碼<script>函數部分)
2):center中豎着的tabs部分:

就是index.vm文件
<html>
<head>
<title></title>
#parse("ui:include")
<script>
$(document).ready(function(){
$("#tt").tabs({
tabPosition:'left',
fit:true,
onSelect:function(title,index){
open(index);
}
});
function open(index){
var tab = $("#tt").tabs("getTab",index);
//console.log(tab);
//console.log(tab[0]);
//不重復打開
if(tab.attr("opend")){
return;
}
var url = tab.panel("options").url;
//var op=tab.panel("options");
//console.log(op);
if(url){
$(tab[0]).html('<iframe frameborder="0" scrolling="auto" width="100%" height="100%" src="${path}'+url+'"></iframe>');
tab.attr("opend",true);
}
}
open(0);
});
</script>
</head>
<body>
<div id="tt" class="easyui-tabs">
<div title="基本實現" style="padding:10px;" data-options="url:'/cn/com/ksplatform/ui/demo/main/views/fcomponents/panel/base.vm'">
</div>
<div title="面板工具欄" style="padding:10px;" data-options="url:'/cn/com/ksplatform/ui/demo/main/views/fcomponents/panel/mbgjl.vm'">
</div>
<div title="自定義工具欄" style="padding:10px;" data-options="url:'/cn/com/ksplatform/ui/demo/main/views/fcomponents/panel/zdygjl.vm'">
</div>
<div title="面板頁腳" style="padding:10px;" data-options="url:'/cn/com/ksplatform/ui/demo/main/views/fcomponents/panel/mbyj.vm'">
</div>
<div title="加載面板內容" style="padding:10px;" data-options="url:'/cn/com/ksplatform/ui/demo/main/views/fcomponents/panel/jzmbnr.vm'">
</div>
<div title="面板嵌套" style="padding:10px;" data-options="url:'/cn/com/ksplatform/ui/demo/main/views/fcomponents/panel/mbqt.vm'">
</div>
<div title="流式面板" style="padding:10px;" data-options="url:'/cn/com/ksplatform/ui/demo/main/views/fcomponents/panel/lsmb.vm'">
</div>
<div title="API" style="padding:10px;" data-options="url:'/cn/com/ksplatform/ui/demo/main/views/fcomponents/panel/api.vm'">
</div>
</div>
</body>
</html>
3):豎着的tabs中的每個小窗口的示例文件:base.vm
<html>
<head>
<title></title>
#parse("ui:include")
</head>
<body>
<h2>基本面板Basic Panel</h2>
<p>面板是其他組件或元素的容器</p>
<div style="margin:20px 0 10px 0;">
<a href="#" class="easyui-linkbutton" onclick="javascript:$('#p').panel('open')">打開</a>
<a href="#" class="easyui-linkbutton" onclick="javascript:$('#p').panel('close')">關閉</a>
</div>
<div id="p" class="easyui-panel" title="Basic Panel" style="width:700px;height:200px;padding:10px;">
<p style="font-size:14px">jQuery EasyUI framework helps you build your web pages easily.</p>
<ul>
<li>easyui is a collection of user-interface plugin based on jQuery.</li>
<li>easyui provides essential functionality for building modem, interactive, javascript applications.</li>
<li>using easyui you don't need to write many javascript code, you usually defines user-interface by writing some HTML markup.</li>
<li>complete framework for HTML5 web page.</li>
<li>easyui save your time and scales while developing your products.</li>
<li>easyui is very easy but powerful.</li>
</ul>
</div>
</body>
</html>
附上:mian.vm中用到的tree.json:
[{ "text":"基礎組件", "children":[ {"text":"面板Panel","url":"/cn/com/ksplatform/ui/demo/main/views/fcomponents/panel/index.vm"}, {"text":"數據表格DataGrid","url":"/cn/com/ksplatform/ui/demo/main/views/fcomponents/datagrid/index.vm"}, {"text":"樹形數據表格TreeGrid","url":"/cn/com/ksplatform/ui/demo/main/views/fcomponents/treegrid/index.vm"}, {"text":"分割按鈕SplitButton","url":"/cn/com/ksplatform/ui/demo/main/views/fcomponents/splitbutton/index.vm"}, {"text":"表單Form","url":"/cn/com/ksplatform/ui/demo/main/views/fcomponents/form/index.vm"}, {"text":"下拉列表框ComboBox","url":"/cn/com/ksplatform/ui/demo/main/views/fcomponents/combobox/index.vm"}, {"text":"數字文本框微調NumberSpinner","url":"/cn/com/ksplatform/ui/demo/main/views/fcomponents/numberspinner/index.vm"}, {"text":"時間框微調TimeSpinner","url":"/cn/com/ksplatform/ui/demo/main/views/fcomponents/timespinner/index.vm"}, {"text":"窗口Window","url":"/cn/com/ksplatform/ui/demo/main/views/fcomponents/window/index.vm"}, {"text":"放置Droppable","url":"/cn/com/ksplatform/ui/demo/main/views/fcomponents/droppable/index.vm"}, {"text":"手風琴菜單Accordion","url":"/cn/com/ksplatform/ui/demo/main/views/fcomponents/accordion/index.vm"}, {"text":"數據列表DataList","url":"/cn/com/ksplatform/ui/demo/main/views/fcomponents/datalist/index.vm"}, {"text":"鏈接按鈕LinkButton","url":"/cn/com/ksplatform/ui/demo/main/views/fcomponents/linkbutton/index.vm"}, {"text":"分頁Pagination","url":"/cn/com/ksplatform/ui/demo/main/views/fcomponents/pagination/index.vm"}, {"text":"文本框TextBox","url":"/cn/com/ksplatform/ui/demo/main/views/fcomponents/textbox/index.vm"}, {"text":"數據表格下拉框ComboGrid","url":"/cn/com/ksplatform/ui/demo/main/views/fcomponents/combogrid/index.vm"}, {"text":"日歷Calendar","url":"/cn/com/ksplatform/ui/demo/main/views/fcomponents/calendar/index.vm"}, {"text":"日期時間框微調DateTimeSpinner","url":"/cn/com/ksplatform/ui/demo/main/views/fcomponents/datatimespinner/index.vm"}, {"text":"對話框Dialog","url":"/cn/com/ksplatform/ui/demo/main/views/fcomponents/dialog/index.vm"}, {"text":"調整大小Resizable","url":"/cn/com/ksplatform/ui/demo/main/views/fcomponents/resizable/index.vm"}, {"text":"選項卡Tabs","url":"/cn/com/ksplatform/ui/demo/main/views/fcomponents/tabs/index.vm"}, {"text":"屬性網格PropertyGrid","url":"/cn/com/ksplatform/ui/demo/main/views/fcomponents/propertygrid/index.vm"}, {"text":"菜單Menu","url":"/cn/com/ksplatform/ui/demo/main/views/fcomponents/menu/index.vm"}, {"text":"進度條ProgressBar","url":"/cn/com/ksplatform/ui/demo/main/views/fcomponents/progressbar/index.vm"}, {"text":"文件框FileBox","url":"/cn/com/ksplatform/ui/demo/main/views/fcomponents/filebox/index.vm"}, {"text":"樹形下拉框ComboTree","url":"/cn/com/ksplatform/ui/demo/main/views/fcomponents/combotree/index.vm"}, {"text":"日期框DateBox","url":"/cn/com/ksplatform/ui/demo/main/views/fcomponents/datebox/index.vm"}, {"text":"滑動條Slider","url":"/cn/com/ksplatform/ui/demo/main/views/fcomponents/slider/index.vm"}, {"text":"消息框Messager","url":"/cn/com/ksplatform/ui/demo/main/views/fcomponents/messager/index.vm"}, {"text":"提示框Tooltip","url":"/cn/com/ksplatform/ui/demo/main/views/fcomponents/tooltip/index.vm"}, {"text":"布局Layout","url":"/cn/com/ksplatform/ui/demo/main/views/fcomponents/layout/index.vm"}, {"text":"樹Tree","url":"/cn/com/ksplatform/ui/demo/main/views/fcomponents/tree/index.vm"}, {"text":"菜單按鈕MenuButton","url":"/cn/com/ksplatform/ui/demo/main/views/fcomponents/menubutton/index.vm"}, {"text":"搜索框SearchBox","url":"/cn/com/ksplatform/ui/demo/main/views/fcomponents/searchbox/index.vm"}, {"text":"自定義下拉框Combo","url":"/cn/com/ksplatform/ui/demo/main/views/fcomponents/combo/index.vm"}, {"text":"數字文本框NumberBox","url":"/cn/com/ksplatform/ui/demo/main/views/fcomponents/numberbox/index.vm"}, {"text":"日期時間框DateTimeBox","url":"/cn/com/ksplatform/ui/demo/main/views/fcomponents/datetimebox/index.vm"}, {"text":"驗證框ValidateBox","url":"/cn/com/ksplatform/ui/demo/main/views/fcomponents/validatebox/index.vm"}, {"text":"拖動Draggable","url":"/cn/com/ksplatform/ui/demo/main/views/fcomponents/draggable/index.vm"} ] },{ "text":"組合組件", "children":[ ] },{ "text":"功能組件", "children":[ {"text":"分頁數據列表"} ] }]
這篇博文的目的主要是學習,各個main.vm和index.vm中<script></script>間函數的寫法,如何能熟練正確的使用easyui各個模塊的屬性和方法:
其中通過chrome瀏覽器的console平台,借助console.log()方法,打印出index.vm文件中比較難理解的幾個變量值:onSelect:function(title,index)中的title和index分別是tabs中各個子窗口的標題和索引號,索引號從0開始;
var tab = $("#tt").tabs("getTab",index); 打印出這里的var tab變量是整個大的頁面;
console.log(tab[0]); 注意console輸出的這個tab[0]恰好是tabs中選中的子窗口頁面;
var url = tab.panel("options").url 中的url就是:/cn/com/ksplatform/ui/demo/main/views/fcomponents/panel/base.vm,也就是在index.vm中每個子窗口的地址;
easyui中tree模塊的屬性:
$("#tree_menu").tree({
onClick: function(node){
console.log(node);
if(!tabs_content.tabs('exists',node.text)){
if(node.url){
addTabs(node);
}
}else{
tabs_content.tabs("select",node.text);
}
}
});
這個函數中的node是什么呢?
這點可以看easyui中tree的api(當然也可以直接console輸出):
每個節點都具備以下屬性:
-
id:節點ID,對加載遠程數據很重要。
-
text:顯示節點文本。
-
state:節點狀態,'open' 或 'closed',默認:'open'。如果為'closed'的時候,將不自動展開該節點。
-
checked:表示該節點是否被選中。
-
attributes: 被添加到節點的自定義屬性。
-
children: 一個節點數組聲明了若干節點。
前端還是經驗的積累,所以多看api!!,多參加實踐!!
