select id,name as text,haschildren=1 AS children from sys_unit
得到的是1
select id,name as text,if(haschildren=1,true,flase) AS children from sys_unit
还是1
select id,name as text,if(haschildren=1,'true','flase') AS children from sys_unit
字符串的true,非我所要也
select id,name as text,haschildren=1 AS children from sys_unit
得到的是1
select id,name as text,if(haschildren=1,true,flase) AS children from sys_unit
还是1
select id,name as text,if(haschildren=1,'true','flase') AS children from sys_unit
字符串的true,非我所要也
var str = [];
if (objs) {
objs.forEach(function (o) {
var obj = {};
obj.id = o.id;
obj.text = o.name;
obj.children = o.children==1;
str.push(obj);
});
}
var json = JSON.stringify(objs, function (key, value) {
if (key == 'children') {
return value == 1;
}
return value;
});
var str=JSON.parse(json);
以上两种写法都是将json对象中的children的1转为true/false,哪种效率更高?我打印执行时间都是0,看不出高下。