MVC2与ExtJs TreePanel的checked关键字问题

失去乐山贼 2011-08-07 12:45:18
MVC2可以把IList<T> 用JsonResult转换JSON数据,我要实现带复选框的Tree,参考地址http://www.mhzg.net/a/20114/20114212300174.html ; 现在我要动态生成JSON,而这个checked是C#的关键字。不能为属性,怎么办?

//实体
public virtual int id { get; set; }

public virtual string text { get; set; }

public virtual bool leaf { get; set; }

public virtual string cls { get; set; }

public virtual IList<UnitType> children{get;set;}

public virtual bool Checked { get; set; }

控制器:

public JsonResult showTree() {
IList<UnitType> types=GetTypes();
return Json(types, JsonRequestBehavior.AllowGet);
}



var store = Ext.create('Ext.data.TreeStore', {
proxy: {
type: 'ajax',
url: '<%= Url.Action("showTree", "Home")%>'//'/Data/check-nodes.json'
},
sorters: [{
property: 'leaf',
direction: 'ASC'
}, {
property: 'text',
direction: 'ASC'
}]
});
var tree = Ext.create('Ext.tree.Panel', {
store: store,
rootVisible: false,
useArrows: true,
frame: true,
title: 'Tree Panel',
renderTo: 'tree-div',
width: 289,
height: 220
});
});

extjs checked小写的会显示复选框。。
官网JSON:[{
"text": "To Do",
"cls": "folder",
"expanded": true,
"children": [{
"text": "Go jogging",
"id" : "3",
"leaf": true,
"checked": true
},{
"text": "Take a nap",
"leaf": true,
"id" : "4",
"checked": false
},{
"text": "Climb Everest",
"leaf": true,
"id" : "5",
"checked": false
}]
},{
"text": "Grocery List",
"cls": "folder",
"children": [{
"text": "Bananas",
"leaf": true,
"id" : "8",
"checked": false
},{
"text": "Milk",
"leaf": true,
"id" : "10",
"checked": false
},{
"text": "Cereal",
"leaf": true,
"id" : "15",
"checked": false
},{
"text": "Energy foods",
"cls": "folder",
"children": [{
"text": "Coffee",
"leaf": true,
"id" : "52",
"checked": false
},{
"text": "Red Bull",
"leaf": true,
"id" : "13",
"checked": false
}]
}]
},{
"text": "Remodel Project",
"cls": "folder",
"children": [{
"text": "Finish the budget",
"leaf": true,
"id" : "34",
"checked": false
},{
"text": "Call contractors",
"leaf": true,
"id" : "103",
"checked": false
},{
"text": "Choose design",
"leaf": true,
"id" : "6",
"checked": false
}]
}]


...全文
360 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
失去乐山贼 2011-08-08
  • 打赏
  • 举报
回复
关键字是可以用的 加上 @符号就ok了,哈哈。
limii 2011-08-08
  • 打赏
  • 举报
回复
up........
阿非 2011-08-08
  • 打赏
  • 举报
回复
匿名类型也不行。

你可以先用Checked 生成相应json串,然后Replace 成小写

之后不用ActionResult 用流来控制输出
阿非 2011-08-08
  • 打赏
  • 举报
回复
你用的vs 什么版本,如果支持匿名类型的话 可使用匿名类型来实现
zthsn 2011-08-08
  • 打赏
  • 举报
回复
纯粹帮顶起来
失去乐山贼 2011-08-08
  • 打赏
  • 举报
回复
顶起来,各位路过的大侠帮帮忙..谢谢啦。
阿非 2011-08-08
  • 打赏
  • 举报
回复
恩,是的. @前缀可令关键字可编译

Keywords are predefined reserved identifiers that have special meanings to the compiler. They cannot be used as identifiers in your program unless they include @ as a prefix. For example, @if is a legal identifier but if is not because it is a keyword.

上午的时候想到@了,只是之前是在Razor中使用@前缀屏蔽关键字 把它当成Razor的语法了
子夜__ 2011-08-07
  • 打赏
  • 举报
回复
换个名字。
失去乐山贼 2011-08-07
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wxr0323 的回复:]

换个名字。
[/Quote]
extjs 认这个checked属性的,换了名字extjs就不认识了,首字母大写的也不行Checked,纠结..

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧