一、 1、官方網址: http://www.ligerui.com/



<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<link href="http://www.cnblogs.com/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<style type="text/css">
</style>
<script src="http://www.cnblogs.com/lib/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="http://www.cnblogs.com/lib/ligerUI/js/core/base.js" type="text/javascript"></script>
<script src="http://www.cnblogs.com/lib/ligerUI/js/plugins/ligerComboBox.js" type="text/javascript"></script>
<script src="http://www.cnblogs.com/lib/ligerUI/js/plugins/ligerResizable.js" type="text/javascript"></script>
<script type="text/javascript"> $(function () { $("#test1").ligerComboBox({ data: [ { text: '張三', id: '1' }, { text: '李四', id: '2' }, { text: '趙武', id: '44' } ], valueFieldID: 'test3' }); }); </script>
</head>
<body style="padding:10px">
<input type="text" id="test1" />
</body>
</html>
效果如圖:
從上面的代碼我們可以看出,首先需要引入對應你風格的皮膚下的ligerui-all.css文件,需要引入jquery文件,需要引入js/core/base.js文件,這個文件就如同你在使用jquery的時候需要引入jquery 的api文件一樣,是個基礎類吧,我個人的理解是這樣。但在ligerui給出的demo中布局頁面沒有使用該文件而使用了/js/ligerui.min.js文件,我在一個項目中嘗試過,如果同時引入了這兩個則會出現錯誤,所以我在使用過程中除了布局頁面,在別的畫面中在引用ligerui別的插件之前都引用base.js文件。其次,你當前頁面使用到了哪些ligerui的控件,則必須引用js/plugins下面對應的js插件。比如上面的例子中使用了ligerui的combox控件,則必須要引用對應的ligerComboBox.js插件。 控件的初始化如例子代碼中的js部分,需要放在$(function(){...})中也就是,不同控件的初始化方法都類似,比如combox的初始化方法為$("...").ligerComboBox({...}), grid的初始化方法為("...").ligerGrid({...}).如上面的例子其中Data參數為該控件數據源參數,在ligerui中所有的數據源只能試用JSON格式,不同插架的具體參數、事件、方法請參考官方api:
在實際的項目中我們的數據源肯定是動態從數據庫中存取,下面我將我在項目中使用的將DataTable轉換為Json格式的類貼出來,有需要的可以拿去用。

public class JsonOperation { /// <summary>
/// DataTable轉換Json /// </summary>
/// <param name="dtSource">轉換數據源</param>
/// <param name="strJosonCols">Joson格式列</param>
/// <param name="strParCols">DataTable格式列</param>
/// <returns>Json字符串</returns>
public static string DataTableToJson(DataTable Source, string[] strJosonCols, string[] strParCols) { StringBuilder Json = new StringBuilder(); Json.Append("["); if (Source.Rows.Count > 0) { for (int intRow = 0; intRow < Source.Rows.Count; intRow++) { Json.Append("{"); for (int intCol = 0; intCol < strJosonCols.Length; intCol++) { Json.Append(strJosonCols[intCol] + ":\"" + Source.Rows[intRow][strParCols[intCol]].ToString().Replace("\"","").Trim() + "\""); if (intCol < strJosonCols.Length - 1) { Json.Append(","); } } Json.Append("}"); if (intRow < Source.Rows.Count - 1) { Json.Append(","); } } } Json.Append("]"); return Json.ToString(); } /// <summary>
/// DataTable轉換Json /// </summary>
/// <param name="dtSource">轉換數據源</param>
/// <returns>Json字符串</returns>
public static string DataTableToJson(DataTable Source) { StringBuilder Json = new StringBuilder(); Json.Append("["); if (Source.Rows.Count > 0) { for (int i = 0; i < Source.Rows.Count; i++) { Json.Append("{"); for (int j = 0; j < Source.Columns.Count; j++) { Json.Append(Source.Columns[j].ColumnName.ToString() + ":\"" + Source.Rows[i][j].ToString() + "\""); if (j < Source.Columns.Count - 1) { Json.Append(","); } } Json.Append("}"); if (i < Source.Rows.Count - 1) { Json.Append(","); } } } Json.Append("]"); return Json.ToString(); } }