对象转换成JSON的时候是这样的:
[[
{ title: 'ID', field: 'KeyId', width: 80 },
{
title: '超管',
field: 'IsAdmin',
width: 80,
align: 'center',
formatter: 'function (v, d, i) {
if (d.UserName == "admin")
return '';
return '<img style="cursor:pointer" title="设置超管" onclick="javascript:setUserAttr(\'isadmin\','+d.KeyId+','+v+')" src="/css/icon/16/bullet_' + (v ? "tick.png" : "minus.png") + '" />';
}'
},
{title:'描述',field:'Re',width:200}
]]实际想要的是这样的
[[
{ title: 'ID', field: 'KeyId', width: 80 },
{
title: '超管',
field: 'IsAdmin',
width: 80,
align: 'center',
formatter: function (v, d, i) {
if (d.UserName == "admin")
return '';
return '<img style="cursor:pointer" title="设置超管" onclick="javascript:setUserAttr(\'isadmin\','+d.KeyId+','+v+')" src="/css/icon/16/bullet_' + (v ? "tick.png" : "minus.png") + '" />';
}
},
{title:'描述',field:'Re',width:200}
]]问题:由于 formatter: 'function (v, d, i) {
if (d.UserName == "admin")
return '';
return '<img style="cursor:pointer" title="设置超管" onclick="javascript:setUserAttr(\'isadmin\','+d.KeyId+','+v+')" src="/css/icon/16/bullet_' + (v ? "tick.png" : "minus.png") + '" />';
}'
被当作字符串用了,所以错误,那位仁兄能帮忙解决下,感激不尽
[[
{ title: 'ID', field: 'KeyId', width: 80 },
{
title: '超管',
field: 'IsAdmin',
width: 80,
align: 'center',
formatter: 'function (v, d, i) {
if (d.UserName == "admin")
return '';
return '<img style="cursor:pointer" title="设置超管" onclick="javascript:setUserAttr(\'isadmin\','+d.KeyId+','+v+')" src="/css/icon/16/bullet_' + (v ? "tick.png" : "minus.png") + '" />';
}'
},
{title:'描述',field:'Re',width:200}
]]实际想要的是这样的
[[
{ title: 'ID', field: 'KeyId', width: 80 },
{
title: '超管',
field: 'IsAdmin',
width: 80,
align: 'center',
formatter: function (v, d, i) {
if (d.UserName == "admin")
return '';
return '<img style="cursor:pointer" title="设置超管" onclick="javascript:setUserAttr(\'isadmin\','+d.KeyId+','+v+')" src="/css/icon/16/bullet_' + (v ? "tick.png" : "minus.png") + '" />';
}
},
{title:'描述',field:'Re',width:200}
]]问题:由于 formatter: 'function (v, d, i) {
if (d.UserName == "admin")
return '';
return '<img style="cursor:pointer" title="设置超管" onclick="javascript:setUserAttr(\'isadmin\','+d.KeyId+','+v+')" src="/css/icon/16/bullet_' + (v ? "tick.png" : "minus.png") + '" />';
}'
被当作字符串用了,所以错误,那位仁兄能帮忙解决下,感激不尽
解决方案 »
- input=file上传图片过大的问题
- 刚刚涉及ajax,运用prototype.js,代码有错
- 讨论:ms ajax + asp.net + sql的整站解决方案
- 调查:URL路径中的中文,如“中文.htm",在服务端编码时应该用Server.UrlEncode还是Server.UrlPathEncode?
- treeview動態添加節點,包括添加,刪除,移動功能
- 60分,求解treeview问题,在线等
- 关于打开文件的问题,急,帮帮忙吧
- 简单问题,即刻揭帖!!!
- 异常详细信息: System.Data.SqlClient.SqlException: 将截断字符串或二进制数据。如何解决。加急。。。在线等!!
- 可以用asp.net做个人网站吗?
- ASP.NET Gridview~~~~
- 求一正则表达式
if (d.UserName == "admin")
return '';
return '<img style="cursor:pointer" title="设置超管" onclick="javascript:setUserAttr(\'isadmin\','+d.KeyId+','+v+')" src="/css/icon/16/bullet_' + (v ? "tick.png" : "minus.png") + '" />';
}然后 formatter:temp,
不会给formatter赋temp的值的
if (d.UserName == "admin")
return '';
return '<img style="cursor:pointer" title="设置超管" onclick="javascript:setUserAttr(\'isadmin\',' + d.KeyId + ',' + v + ')" src="/css/icon/16/bullet_' + (v ? "tick.png" : "minus.png") + '" />';
}
[[
{ title: 'ID', field: 'KeyId', width: 80 },
{
title: '超管',
field: 'IsAdmin',
width: 80,
align: 'center',
formatter: '' + temp + '',
},
{title:'描述',field:'Re',width:200}
]]
if (d.UserName == "admin")
return '';
return '<img style="cursor:pointer" title="设置超管" onclick="javascript:setUserAttr(\'isadmin\',' + d.KeyId + ',' + v + ')" src="/css/icon/16/bullet_' + (v ? "tick.png" : "minus.png") + '" />';
}
[[
{ title: 'ID', field: 'KeyId', width: 80 },
{
title: '超管',
field: 'IsAdmin',
width: 80,
align: 'center',
formatter: '' + temp + '',
},
{title:'描述',field:'Re',width:200}
]]
if (d.UserName == "admin")
return '';
return '<img style="cursor:pointer" title="设置超管" onclick="javascript:setUserAttr(\'isadmin\',' + d.KeyId + ',' + v + ')" src="/css/icon/16/bullet_' + (v ? "tick.png" : "minus.png") + '" />';
}
[[
{ title: 'ID', field: 'KeyId', width: 80 },
{
title: '超管',
field: 'IsAdmin',
width: 80,
align: 'center',
formatter: '' + temp + '',
},
{title:'描述',field:'Re',width:200}
]] 这个也不行吗?
再试试
if (d.UserName == ‘admin’)
return '';
return '<img style=\"cursor:pointer\" title=\" 设置超管\" onclick=\" javascript:setUserAttr(\'isadmin\','+d.KeyId+','+v+')" src="/css/icon/16/bullet_' + (v ? "tick.png" : "minus.png") + '\" />';
}”
function test(v, d, i) {
if (d.UserName == "admin")
return '';
return '<img style="cursor:pointer" title="设置超管" onclick="javascript:setUserAttr(\'isadmin\','+d.KeyId+','+v+')" src="/css/icon/16/bullet_' + (v ? "tick.png" : "minus.png") + '" />';formatter:test
formatter:test 这个是JSON出来的数据 应该是 formatter:"test" 在这种情况下调用test
alert(v);
}
var root = [[{
title: 'ID',
field: 'KeyId',
width: 80
},
{
title: '超管',
field: 'IsAdmin',
width: 80,
align: 'center',
formatter: 'temp(1)'
},
{
title: '描述',
field: 'Re',
width: 200
}]];
$(root[0]).each(function(i, o) {
if (o.formatter) eval(o.formatter);
})
$(function () {
$('#tt').datagrid({
idField: 'id',
singleSelect: true,
url: '../Handler/ProjectHandler.ashx?type=Find',
columns: [[
{ field: 'ProjectName', title: '项目名称', width: $(this).width() * 0.1 },
{ field: 'ProjectType', title: '项目类别', width: $(this).width() * 0.07, formatter: getType },
{ field: 'BelongDepart', title: '归口部门', width: $(this).width() * 0.1, formatter: getDep },
{ field: 'AssumeDepart', title: '承担单位', width: $(this).width() * 0.15 },
{ field: 'DeclaredTime', title: '申报时间', width: $(this).width() * 0.15 },
{ field: 'DeclarationFunds', title: '申请经费', width: $(this).width() * 0.08 },
{ field: 'TotalFunds', title: '项目总经费', width: $(this).width() * 0.08 },
{ field: 'ProjectPrincipal', title: '项目负责人', width: $(this).width() * 0.08 },
{ field: 'DeclaredTime', title: '填报时间', width: $(this).width() * 0.1, formatter: formatterdate }
]],
pagination: true,
rownumbers: true
});
var p = $('#tt').datagrid('getPager');
$(p).pagination({
pageSize: 15,//每页显示的记录条数,默认为10
pageList: [15, 30, 45],//可以设置每页记录条数的列表
beforePageText: '第',//页数文本框前显示的汉字
afterPageText: '页 共 {pages} 页',
displayMsg: '当前显示 {from} - {to} 条记录 共 {total} 条记录'
});
}); //获取项目类别
function getType(value) {
var temp = null;
$.ajax({
type: 'GET',
async: false,
url: '../Handler/ProjectHandler.ashx?type=Query&typeId=' + value,
success: function (data) {
temp = data
}
});
return temp;
} //获取归口部门
function getDep(value) {
var temp = null;
$.ajax({
type: 'GET',
async: false,
url: '../Handler/Department.ashx?type=Query&id=' + value,
success: function (data) {
temp = data
}
});
return temp;
}
我的项目里面的 有问题么?
formatter:"test" 你确定?
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Format DataGrid Columns - jQuery EasyUI Demo</title>
<link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../../themes/icon.css">
<link rel="stylesheet" type="text/css" href="../demo.css">
<script type="text/javascript" src="../../jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="../../jquery.easyui.min.js"></script>
</head>
<body>
<h2>Format DataGrid Columns</h2>
<div class="demo-info">
<div class="demo-tip icon-tip"></div>
<div>The list price value will show red color when less than 30.</div>
</div>
<div style="margin:10px 0;"></div>
<table class="easyui-datagrid" title="Format DataGrid Columns" style="width:700px;height:250px"
data-options="rownumbers:true,singleSelect:true,iconCls:'icon-ok',url:'../datagrid/datagrid_data1.json'">
<thead>
<tr>
<th data-options="field:'itemid',width:80">Item ID</th>
<th data-options="field:'productid',width:100">Product</th>
<th data-options="field:'listprice',width:80,align:'right',formatter:formatPrice">List Price</th>
<th data-options="field:'unitcost',width:80,align:'right'">Unit Cost</th>
<th data-options="field:'attr1',width:240">Attribute</th>
<th data-options="field:'status',width:60,align:'center'">Status</th>
</tr>
</thead>
</table>
<script>
function formatPrice(val,row){
if (val < 30){
return '<span style="color:red;">('+val+')</span>';
} else {
return val;
}
}
</script>
</body>
</html> 这是官网的实例。。哪个告诉你要用 formatter:"test" 函数名 加双引号使用的?