版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/OnlyRu/article/details/80061612
$(function () {
//动态树形菜单数据
var treeData = [{
text : "Hbase查询功能列表",
children : [{
text : "具体数据查询",
children : [{
text : "单一商品价格库存",
attributes : {
url : '<iframe width="100%" height="100%" frameborder="0" src="jsp/queryPriceStock.jsp" style="width:100%;height:100%;margin:0px 0px;"></iframe>'
}
}, {
text : "单一商品价格库存2",
attributes : {
url : ''
}
}
]
},{
text : "数据量查询",
children : [{
text : "总量统计",
attributes : {
url : '<iframe width="100%" height="100%" frameborder="0" src="jsp/queryPriceStock.jsp" style="width:100%;height:100%;margin:0px 0px;"></iframe>'
}
}, {
text : "总量统计2",
attributes : {
url : ''
}
}
]
}
]
}
];
//实例化树形菜单
$("#tree").tree({
data : treeData,
lines : true,
onClick : function (node) {
if (node.attributes) {
Open(node.text, node.attributes.url);
}
}
});
//在右边center区域打开菜单,新增tab
function Open(text, url) {
if ($("#tabs").tabs('exists', text)) {
$('#tabs').tabs('select', text);
} else {
$('#tabs').tabs('add', {
title : text,
closable : true,
content : url
});
}
}
//绑定tabs的右键菜单
$("#tabs").tabs({
onContextMenu : function (e, title) {
e.preventDefault();
$('#tabsMenu').menu('show', {
left : e.pageX,
top : e.pageY
}).data("tabTitle", title);
}
});
//实例化menu的onClick事件
$("#tabsMenu").menu({
onClick : function (item) {
CloseTab(this, item.name);
}
});
//几个关闭事件的实现
function CloseTab(menu, type) {
var curTabTitle = $(menu).data("tabTitle");
var tabs = $("#tabs");
if (type === "close") {
tabs.tabs("close", curTabTitle);
return;
}
var allTabs = tabs.tabs("tabs");
var closeTabsTitle = [];
$.each(allTabs, function () {
var opt = $(this).panel("options");
if (opt.closable && opt.title != curTabTitle && type === "Other") {
closeTabsTitle.push(opt.title);
} else if (opt.closable && type === "All") {
closeTabsTitle.push(opt.title);
}
});
for (var i = 0; i < closeTabsTitle.length; i++) {
tabs.tabs("close", closeTabsTitle[i]);
}
}
});
/// <summary>
/// Msdn
/// </summary>
/// <param name="jsonName"></param>
/// <param name="dt"></param>
/// <returns></returns>
public static string DataTableToJson(string jsonName, DataTable dt)
{
StringBuilder Json = new StringBuilder();
Json.Append("{\"" + jsonName + "\":[");
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
Json.Append("{");
for (int j = 0; j < dt.Columns.Count; j++)
{
Json.Append("\"" + dt.Columns[j].ColumnName.ToString() + "\":\"" + dt.Rows[i][j].ToString() + "\"");
if (j < dt.Columns.Count - 1)
{
Json.Append(",");
}
}
Json.Append("}");
if (i < dt.Rows.Count - 1)
{
Json.Append(",");
}
}
}
Json.Append("]}");
return Json.ToString();
}
}
<table>
<tr>
<td>
<div>部门名称: </div>
<select style="margin-bottom: 20px; margin-right: 20px; width: 200px; height: 32px;" class="easyui-combotree" id="seleDepartName" name="city" />
</td>
<td>
<div>
<div>公司:</div>
<input style="margin-bottom: 20px; margin-right: 20px; width: 200px; height: 32px;" id="seleCompanyId" class="easyui-combobox"
name="language"
data-options="
url:'../api/xxx',
method:'get',
valueField:'CompanyId',
textField:'CompanyName',
panelHeight:'auto',
editable:false,
required:true">
</div>
</td>
</tr>
<tr>
<td>
<div style="float: none; width: 200px; margin-top: 50px;">
<div>
<a href="#" class="easyui-linkbutton" id="btnSubmit" style="width: 100%; height: 32px">提交</a>
</div>
</div>
</td>
</tr>
</table>
$('#seleDepartName').combotree({
url: "../Depart/Test",
method: 'get',
loadFilter: function (rows) {
return convert(rows);
}
});
function convert(rows) {
function exists(rows, ParentDepartId) {
for (var i = 0; i < rows.length; i++) {
if (rows[i].DepartId === ParentDepartId) return true;
}
return false;
}
debugger;
var nodes = [];
// get the top level nodes
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
if (!exists(rows, row.ParentDepartId)) {
nodes.push({
id: row.DepartId,
text: row.DepartName
});
}
}
var toDo = [];
for (var i = 0; i < nodes.length; i++) {
toDo.push(nodes[i]);
}
while (toDo.length) {
var node = toDo.shift(); // the parent node
// get the children nodes
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
if (row.ParentDepartId == node.id) {
var child = { id: row.DepartId, text: row.DepartName };
if (node.children) {
node.children.push(child);
} else {
node.children = [child];
}
toDo.push(child);
}
}
}
return nodes;
}
function myformatter(date){
var y = date.getFullYear();
var m = date.getMonth()+1;
var d = date.getDate();
return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);
}
function myparser(s){
if (!s) return new Date();
var ss = (s.split('-'));
var y = parseInt(ss[0],10);
var m = parseInt(ss[1],10);
var d = parseInt(ss[2],10);
if (!isNaN(y) && !isNaN(m) && !isNaN(d)){
return new Date(y,m-1,d);
} else {
return new Date();
}
}
//页面加载
$(function(){
//设置时间
var curr_time = new Date();
$("#txtBeginTime").datebox("setValue",myformatter(curr_time));
$("#txtEndTime").datebox("setValue",myformatter(curr_time));
//获取时间
var beginTime=$("#txtBeginTime").datebox("getValue");
var endTime=$("#txtEndTime").datebox("getValue");
});
$('#tt').datagrid({
title:'Frozen Columns',
iconCls:'icon-save',
width:500,
height:250,
url:'data/datagrid_data.json',
frozenColumns:[[
{field:'itemid',title:'Item ID',width:80},
{field:'productid',title:'Product ID',width:80},
]],
columns:[[
{field:'listprice',title:'List Price',width:80,align:'right'},
{field:'unitcost',title:'Unit Cost',width:80,align:'right'},
{field:'attr1',title:'Attribute',width:100},
{field:'status',title:'Status',width:60}
]]
});
DataTable到string
/// <summary>
/// DataTable 到 string
/// </summary>
/// <param name="dt"></param>
/// <returns></returns>
public static string DataTableToString(DataTable dt)
{
//!@&,#$%,^&*为字段的拼接字符串
//为了防止连接字符串不在DataTable数据中存在,特意将拼接字符串写成特殊的字符!
StringBuilder strData = new StringBuilder();
StringWriter sw = new StringWriter();
//DataTable 的当前数据结构以 XML 架构形式写入指定的流
dt.WriteXmlSchema(sw);
strData.Append(sw.ToString());
sw.Close();
strData.Append("@&@");
for (int i = 0; i < dt.Rows.Count; i++) //遍历dt的行
{
DataRow row = dt.Rows[i];
if (i > 0) //从第二行数据开始,加上行的连接字符串
{
strData.Append("#$%");
}
for (int j = 0; j < dt.Columns.Count; j++) //遍历row的列
{
if (j > 0) //从第二个字段开始,加上字段的连接字符串
{
strData.Append("^&*");
}
strData.Append(Convert.ToString(row[j])); //取数据
}
}
return strData.ToString();
}
string到DataTable
/// <summary>
/// string 到 DataTable
/// </summary>
/// <param name="strdata"></param>
/// <returns></returns>
public static DataTable StringToDataTable(string strdata)
{
if (string.IsNullOrEmpty(strdata))
{
return null;
}
DataTable dt = new DataTable();
string[] strSplit = { "@&@" };
string[] strRow = { "#$%" }; //分解行的字符串
string[] strColumn = { "^&*" }; //分解字段的字符串
string[] strArr = strdata.Split(strSplit, StringSplitOptions.None);
StringReader sr = new StringReader(strArr[0]);
dt.ReadXmlSchema(sr);
sr.Close();
string strTable = strArr[1]; //取表的数据
if (!string.IsNullOrEmpty(strTable))
{
string[] strRows = strTable.Split(strRow, StringSplitOptions.None); //解析成行的字符串数组
for (int rowIndex = 0; rowIndex < strRows.Length; rowIndex++) //行的字符串数组遍历
{
string vsRow = strRows[rowIndex]; //取行的字符串
string[] vsColumns = vsRow.Split(strColumn, StringSplitOptions.None); //解析成字段数组
dt.Rows.Add(vsColumns);
}
}
return dt;
}
//动态树形菜单数据
var treeData = [{
text : "Hbase查询功能列表",
children : [{
text : "具体数据查询",
children : [{
text : "单一商品价格库存",
attributes : {
url : '<iframe width="100%" height="100%" frameborder="0" src="jsp/queryPriceStock.jsp" style="width:100%;height:100%;margin:0px 0px;"></iframe>'
}
}, {
text : "单一商品价格库存2",
attributes : {
url : ''
}
}
]
},{
text : "数据量查询",
children : [{
text : "总量统计",
attributes : {
url : '<iframe width="100%" height="100%" frameborder="0" src="jsp/queryPriceStock.jsp" style="width:100%;height:100%;margin:0px 0px;"></iframe>'
}
}, {
text : "总量统计2",
attributes : {
url : ''
}
}
]
}
]
}
];
//实例化树形菜单
$("#tree").tree({
data : treeData,
lines : true,
onClick : function (node) {
if (node.attributes) {
Open(node.text, node.attributes.url);
}
}
});
//在右边center区域打开菜单,新增tab
function Open(text, url) {
if ($("#tabs").tabs('exists', text)) {
$('#tabs').tabs('select', text);
} else {
$('#tabs').tabs('add', {
title : text,
closable : true,
content : url
});
}
}
//绑定tabs的右键菜单
$("#tabs").tabs({
onContextMenu : function (e, title) {
e.preventDefault();
$('#tabsMenu').menu('show', {
left : e.pageX,
top : e.pageY
}).data("tabTitle", title);
}
});
//实例化menu的onClick事件
$("#tabsMenu").menu({
onClick : function (item) {
CloseTab(this, item.name);
}
});
//几个关闭事件的实现
function CloseTab(menu, type) {
var curTabTitle = $(menu).data("tabTitle");
var tabs = $("#tabs");
if (type === "close") {
tabs.tabs("close", curTabTitle);
return;
}
var allTabs = tabs.tabs("tabs");
var closeTabsTitle = [];
$.each(allTabs, function () {
var opt = $(this).panel("options");
if (opt.closable && opt.title != curTabTitle && type === "Other") {
closeTabsTitle.push(opt.title);
} else if (opt.closable && type === "All") {
closeTabsTitle.push(opt.title);
}
});
for (var i = 0; i < closeTabsTitle.length; i++) {
tabs.tabs("close", closeTabsTitle[i]);
}
}
});
/// <summary>
/// Msdn
/// </summary>
/// <param name="jsonName"></param>
/// <param name="dt"></param>
/// <returns></returns>
public static string DataTableToJson(string jsonName, DataTable dt)
{
StringBuilder Json = new StringBuilder();
Json.Append("{\"" + jsonName + "\":[");
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
Json.Append("{");
for (int j = 0; j < dt.Columns.Count; j++)
{
Json.Append("\"" + dt.Columns[j].ColumnName.ToString() + "\":\"" + dt.Rows[i][j].ToString() + "\"");
if (j < dt.Columns.Count - 1)
{
Json.Append(",");
}
}
Json.Append("}");
if (i < dt.Rows.Count - 1)
{
Json.Append(",");
}
}
}
Json.Append("]}");
return Json.ToString();
}
}
<table>
<tr>
<td>
<div>部门名称: </div>
<select style="margin-bottom: 20px; margin-right: 20px; width: 200px; height: 32px;" class="easyui-combotree" id="seleDepartName" name="city" />
</td>
<td>
<div>
<div>公司:</div>
<input style="margin-bottom: 20px; margin-right: 20px; width: 200px; height: 32px;" id="seleCompanyId" class="easyui-combobox"
name="language"
data-options="
url:'../api/xxx',
method:'get',
valueField:'CompanyId',
textField:'CompanyName',
panelHeight:'auto',
editable:false,
required:true">
</div>
</td>
</tr>
<tr>
<td>
<div style="float: none; width: 200px; margin-top: 50px;">
<div>
<a href="#" class="easyui-linkbutton" id="btnSubmit" style="width: 100%; height: 32px">提交</a>
</div>
</div>
</td>
</tr>
</table>
$('#seleDepartName').combotree({
url: "../Depart/Test",
method: 'get',
loadFilter: function (rows) {
return convert(rows);
}
});
function convert(rows) {
function exists(rows, ParentDepartId) {
for (var i = 0; i < rows.length; i++) {
if (rows[i].DepartId === ParentDepartId) return true;
}
return false;
}
debugger;
var nodes = [];
// get the top level nodes
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
if (!exists(rows, row.ParentDepartId)) {
nodes.push({
id: row.DepartId,
text: row.DepartName
});
}
}
var toDo = [];
for (var i = 0; i < nodes.length; i++) {
toDo.push(nodes[i]);
}
while (toDo.length) {
var node = toDo.shift(); // the parent node
// get the children nodes
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
if (row.ParentDepartId == node.id) {
var child = { id: row.DepartId, text: row.DepartName };
if (node.children) {
node.children.push(child);
} else {
node.children = [child];
}
toDo.push(child);
}
}
}
return nodes;
}
function myformatter(date){
var y = date.getFullYear();
var m = date.getMonth()+1;
var d = date.getDate();
return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);
}
function myparser(s){
if (!s) return new Date();
var ss = (s.split('-'));
var y = parseInt(ss[0],10);
var m = parseInt(ss[1],10);
var d = parseInt(ss[2],10);
if (!isNaN(y) && !isNaN(m) && !isNaN(d)){
return new Date(y,m-1,d);
} else {
return new Date();
}
}
//页面加载
$(function(){
//设置时间
var curr_time = new Date();
$("#txtBeginTime").datebox("setValue",myformatter(curr_time));
$("#txtEndTime").datebox("setValue",myformatter(curr_time));
//获取时间
var beginTime=$("#txtBeginTime").datebox("getValue");
var endTime=$("#txtEndTime").datebox("getValue");
});
$('#tt').datagrid({
title:'Frozen Columns',
iconCls:'icon-save',
width:500,
height:250,
url:'data/datagrid_data.json',
frozenColumns:[[
{field:'itemid',title:'Item ID',width:80},
{field:'productid',title:'Product ID',width:80},
]],
columns:[[
{field:'listprice',title:'List Price',width:80,align:'right'},
{field:'unitcost',title:'Unit Cost',width:80,align:'right'},
{field:'attr1',title:'Attribute',width:100},
{field:'status',title:'Status',width:60}
]]
});
DataTable到string
/// <summary>
/// DataTable 到 string
/// </summary>
/// <param name="dt"></param>
/// <returns></returns>
public static string DataTableToString(DataTable dt)
{
//!@&,#$%,^&*为字段的拼接字符串
//为了防止连接字符串不在DataTable数据中存在,特意将拼接字符串写成特殊的字符!
StringBuilder strData = new StringBuilder();
StringWriter sw = new StringWriter();
//DataTable 的当前数据结构以 XML 架构形式写入指定的流
dt.WriteXmlSchema(sw);
strData.Append(sw.ToString());
sw.Close();
strData.Append("@&@");
for (int i = 0; i < dt.Rows.Count; i++) //遍历dt的行
{
DataRow row = dt.Rows[i];
if (i > 0) //从第二行数据开始,加上行的连接字符串
{
strData.Append("#$%");
}
for (int j = 0; j < dt.Columns.Count; j++) //遍历row的列
{
if (j > 0) //从第二个字段开始,加上字段的连接字符串
{
strData.Append("^&*");
}
strData.Append(Convert.ToString(row[j])); //取数据
}
}
return strData.ToString();
}
string到DataTable
/// <summary>
/// string 到 DataTable
/// </summary>
/// <param name="strdata"></param>
/// <returns></returns>
public static DataTable StringToDataTable(string strdata)
{
if (string.IsNullOrEmpty(strdata))
{
return null;
}
DataTable dt = new DataTable();
string[] strSplit = { "@&@" };
string[] strRow = { "#$%" }; //分解行的字符串
string[] strColumn = { "^&*" }; //分解字段的字符串
string[] strArr = strdata.Split(strSplit, StringSplitOptions.None);
StringReader sr = new StringReader(strArr[0]);
dt.ReadXmlSchema(sr);
sr.Close();
string strTable = strArr[1]; //取表的数据
if (!string.IsNullOrEmpty(strTable))
{
string[] strRows = strTable.Split(strRow, StringSplitOptions.None); //解析成行的字符串数组
for (int rowIndex = 0; rowIndex < strRows.Length; rowIndex++) //行的字符串数组遍历
{
string vsRow = strRows[rowIndex]; //取行的字符串
string[] vsColumns = vsRow.Split(strColumn, StringSplitOptions.None); //解析成字段数组
dt.Rows.Add(vsColumns);
}
}
return dt;
}