EasyUI tree 筆記(1)& javascript url 有中文 變亂碼問題
這幾天做到 Tree
Surl = "/QList/A_Qus_work?cmd_id=" + cid+"&Qn='"+id+"'";
method: 'get',//如果後臺有用 [HttpGet] 就要加這行
});
id
text
state
children
{
public int id;
public string text;
public string state;
public List<Tree_Ui> children=new List<Tree_Ui>();
}
{
//跟ID無關 跟加入層數有關
List<Tree_Ui> Tree = new List<Tree_Ui>();
Tree_Ui a1 = new Tree_Ui();
a1.id = 1; a1.text = "總統府";
Tree.Add(a1);
Tree_Ui b1 = new Tree_Ui();
b1.id = 7; b1.text = "行政院";
a1.children.Add(b1);
Tree_Ui c1 = new Tree_Ui();
c1.text = "內政部";
b1.children.Add(c1);
Tree_Ui b2 = new Tree_Ui();
b2.text = "立法院";
a1.children.Add(b2);
return Tree;
}
{
return Content(JsonConvert.SerializeObject(Tree_Test()), "application/json");
}
前台是
Html
<div id="QusTree" > </div>js:
id =encodeURIComponent(id);// 要傳的有中文的話要轉一下 不然後臺會收到亂碼Surl = "/QList/A_Qus_work?cmd_id=" + cid+"&Qn='"+id+"'";
$('#QusTree').tree({
url: Surl,method: 'get',//如果後臺有用 [HttpGet] 就要加這行
});
後臺:
傳回的json 格式有幾個重點id
text
state
children
所以先宣告一個 class
public class Tree_Ui{
public int id;
public string text;
public string state;
public List<Tree_Ui> children=new List<Tree_Ui>();
}
//製造一個 Tree
public List<Tree_Ui> Tree_Test(){
//跟ID無關 跟加入層數有關
List<Tree_Ui> Tree = new List<Tree_Ui>();
Tree_Ui a1 = new Tree_Ui();
a1.id = 1; a1.text = "總統府";
Tree.Add(a1);
Tree_Ui b1 = new Tree_Ui();
b1.id = 7; b1.text = "行政院";
a1.children.Add(b1);
Tree_Ui c1 = new Tree_Ui();
c1.text = "內政部";
b1.children.Add(c1);
Tree_Ui b2 = new Tree_Ui();
b2.text = "立法院";
a1.children.Add(b2);
return Tree;
}
control:
public ActionResult A_Tree_Test(){
return Content(JsonConvert.SerializeObject(Tree_Test()), "application/json");
}
留言
張貼留言