前言:
話說到新的公司已經呆了三個星期了,從上班的第二天開始就一直在寫項目文檔和給開發人員培訓,以至於我的QQ簽名從"我不是來搞培訓的“到最后直接換成”我是來搞培訓的“。
雖然掛名開發經理,但下面目前就2人,手下的人雖然混過了2年工齡,但連進程,線程,泛型,面向對象等基礎都摸不着頭腦的小女孩,要指望她們寫代碼,只好時不時的抽空給講基礎了。
話說下周的下周還會從Boss的母校里招來二十幾個學生過來實習,要我分解項目,寫出詳細的文檔,然后簡單培訓下學生,讓學生看着文檔就能干活,明白了我是來搞培訓的。
好了,玩笑過后,下面講講當前用EasyUI遇到的幾點問題:
1:兼容IE8問題
話說當前最新版本easyUI 1.3.4不支持ie8,聽說是jq2.0不支持的原因,只好降級使用到easyui 1.3.2,對應的jq1.8版本。
2:Form表單的CheckBox問題
easyUI有個Form表單的自動賦值:$("#id").form('load',json);
一開始用這樣的代碼:
{
if (action.Fill(ID))
{
return action.Data.ToJson();
}
}
結果發現返回的json怎么也給checkbox賦不了值,網上也沒對應的資料好尋,最后調一下js,看到普通的input賦值,想到了on。
於是把返回的true替換成on,[action.Data.ToJson().Replace("True", "on")] 就可以了。
3:DataGrid里的CheckBox問題:
對於表格,需要將某些bool型的字段格式化成checkbox顯示,找到了半天,發現只有用formatter格式化出來自己的樣式:
if (value == " 1 " || value == " True ") {
return " <input type='checkbox' checked='checked' disabled='disabled' /> ";
} else {
return " <input type='checkbox' disabled='disabled' /> ";
}
}
然后界面指定:
悲催的是,格式出來的控件,沒有對應的API可以獲取相關的值,目前的處理方法只好通過增加點擊事件,來處理后續狀態改變后值的提交。
4:Tree 的綁定(MDataTable表格直接轉Json,不用多次查詢數據庫):
研究了一下Tree的綁定的json格式,然后寫了一個遞歸函數,直接把一個MDataTable轉成樹型的Json。
/// <summary>
/// 將表格轉成Tree對應的Json,對應的字段為(id,parentiID,text,state,url)
/// </summary>
/// <param name="dt"></param>
/// <param name="parentID"> 為0或為空 </param>
/// <returns></returns>
public static string ToTreeJson(MDataTable dt, string parentID)
{
List<MDataRow> firstDt = dt.FindAll( " ParentID=' " + parentID + " ' "); // 第一級菜單
if (firstDt.Count > 0)
{
MDataRow row = null;
JsonHelper json = new JsonHelper();
string id, text, url;
for ( int i = 0; i < firstDt.Count; i++)
{
row = firstDt[i];
id = row.Get< string>( " id ");
text = row.Get< string>( " text ");
json.Add( " id ", id);
json.Add( " text ", text);
url = row.Get< string>( " url ");
if (! string.IsNullOrEmpty(url))
{
json.Add( " attributes ", " {\"url\":\" " + url + " \"} ", true);
}
string children = ToTreeJson(dt, id);
if (! string.IsNullOrEmpty(children))
{
if (row.Get< bool>( " state "))
{
json.Add( " state ", " closed ");
}
json.Add( " children ", children, true);
}
json.AddBr();
}
return json.ToString( true);
}
return string.Empty;
}
對於傳進來的MDataTable,需要修改列名和對應的字段對上,然后保留一個通用的上級字段(ParentID)就可以了,最終就出來這種格式了。
5:TreeGrid的綁定:
在功能權限這一塊,需要用到TreeGrid這種格式,最終發現決定上下級的json,是叫“_parentId”,還有該字段不能指定一個不存在的上級,不然不顯示。
對於這個,我也寫了一個簡單的轉換函數:
/// 將表格轉成GreeGrid對應的Json.
/// </summary>
/// <param name="dt"></param>
/// <returns></returns>
public static string ToTreeGridJson(MDataTable dt)
{
int index = dt.Columns.GetIndex( " ParentID ");
if (index > - 1)
{
dt.Columns[index].ColumnName = " _parentId ";
int value = 0;
foreach (MDataRow row in dt.Rows)
{
value = row.Get< int>(index);
if (value == 0 || row.Get< int>( " id ") == value) // GreeGrid不存在的父ID不能出現
{
row[index].Value = DBNull.Value;
}
}
}
return dt.ToJson( true, false);
}
樹形的效果就出來了:
目前項目剛開始,只遇到並處理了這幾個基本的問題,后續若有問題待定。
總結:
話說男女搭配,干活不累,是有那么點道理。