动态加载的菜单列表点击事件
想用easyui写个简易的管理系统,要求是点击左边的菜单栏后,右边会新建一个tab,下面是编写的代码,为什么点击菜单后不新建tab啊?求高人指点。
html部分:
<div data-options="region: 'west', width: 240, split: true, border: false, title: 'Navigate'">
<div id="tree-box" class="easyui-accordion"></div>
</div>
<div data-options="region: 'center'">
<div id="center" class="easyui-tabs" data-options="fit: true, border: false">
<div title="Welcome" data-options="href: 'test.html'" style="padding: 15px"></div>
</div>
</div>
js部分:
$(function () {
$.ajax({
url: "http://192.168.1.103:8080/lesson02/user/getMenu",
type: "get",
dataType: "json",
success: function (data) {
$.each(data, function (index, content) {
var childContent = "";
var child = content.children;
for (var i = 0; i < child.length; i++) {
childContent += "<a class='menu-item' href='" + child[i].url + "'>" + child[i].text + "</a>";
}
$("#tree-box").accordion("add", {
title: content.text,
url: content.url,
content: childContent
});
});
}
});
function treeClick() {
var $items = $("#tree-box").find(".menu-item");
$items.bind("click", treeSelect);
}
function treeSelect() {
var _this = $(this);
var title = _this.text();
var url = _this.attr("href");
addTab(title, url);
return false;
}
function addTab(_title, _url) {
var boxId = "#center";
if($(boxId).tabs("exists", _title)){
$(boxId).tabs("select", _title);
}else{
var _content = "<iframe frameborder = '0' src = '" + _url + "' style = 'width: 100%; height: 100%'></iframe>"
$(boxId).tabs("add", {
title: _title,
content: _content,
closable: true
});
}
}
});