首页 新闻 赞助 找找看

JSON.stringify将对象转换为字符串时属性styler丢失,其他属性无异常

0
[已解决问题] 解决于 2016-06-15 14:49
背景:正在研究easyui  datagride 初始化参数,想用字符串拼接的方式连接两个对象
将整体作为datagride初始化参数,可是属性styler 总是不生效,打印出来发现对象
转换为字符串竟然没有这个属性!!后来用for in 遍历对象直接连接对象就可以了,可是为啥JSON.stringify
会一直把styler属性去掉!!!
var
obj={
//striped: true,//奇偶行变色
columns: [[
{field: 'itemid', title: 'Item ID',styler:cellStyler,rowspan: 2, width: 80,sortable: true},//测试行
{field: 'productid', title: 'Product ID', rowspan: 2, width: 80, sortable: true},
{title: 'Item Details', colspan: 4}
], [
{field: 'listprice', title: 'List Price', width: 80, align: 'right', sortable: true},
{field: 'unitcost', title: 'Unit Cost', width: 80, align: 'right', sortable: true},
{field: 'attr1', title: 'Attribute', width: 100},
{field: 'status', title: 'Status', width: 60}
]]
};
console.log(obj);
console.log(JSON.stringify(obj));//这时属性styler就消失了!!
function cellStyler(value,row,index){
if (index%2===0){
return 'background-color:#ffee00;color:red;';
}
}

很奇怪的现象!!!!!!obj 通过
JSON.stringify  转换之后  style 属性就消失了!!!!!为啥!!!!



LoganNi的主页 LoganNi | 初学一级 | 园豆:140
提问于:2016-06-12 17:17
< >
分享
最佳答案
0

styler是的值是一个function对象,所以不会解析成json

 

奖励园豆:5
刘宏玺 | 专家六级 |园豆:14020 | 2016-06-12 21:46

有办法能检测出来吗,在easyui.js里找到有这个字段,但是在引入了easyui.js的html页面中访问不到styler变量,如果直接访问用于配置的对象里的styler字段,检测是 string类型,请教下怎么直接访问到他。

 

console.log(Object.prototype.toString.call(styler));

//页面引入了 easyui.js 并且可以正常显示,但是访问不到styler变量

// Uncaught ReferenceError: styler is not defined

 

 

var ary=[
{field: 'itemid', title: 'Item ID',styler:cellStyler,rowspan: 2, width: 80,sortable: true},
{field: 'productid', title: 'Product ID', rowspan: 2, width: 80, sortable: true},
{title: 'Item Details', colspan: 4}
];

for(var key in ary[0]){
console.log(Object.prototype.toString.call(key));
}
//把配置对象里有styler的隔离出来检测类型 都是string

LoganNi | 园豆:140 (初学一级) | 2016-06-13 10:50
其他回答(1)
0

styler 还是 style

长蘑菇星人 | 园豆:1832 (小虾三级) | 2016-06-12 17:29

styler  easyUi里 datagrid 初始化时候的一个属性

支持(0) 反对(0) LoganNi | 园豆:140 (初学一级) | 2016-06-13 09:05
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册