返回的json对象不能太复杂,
对象得有get、set方法
import lombok.Data;
@Data
public class UserNode {
private String id; //id
private String loginName; //登录名
private String name; //名称
private String officeId;
private int seclevel;
public UserNode(){
}
public UserNode(UserInfo userInfo){
this.id = userInfo.getId();
this.loginName = userInfo.getLoginName();
this.name = userInfo.getName();
this.officeId = userInfo.getOfficeId();
this.seclevel = userInfo.getSeclevel();
}
}
@RequestMapping(value = "/getUsersOfOffice", method = RequestMethod.POST)
@ResponseBody
public List<UserNode> getUsersOfOffice(Model model, String orgId) {
}
function selectOffice(orgSelected) {
let orgId = "";
var orgSelect=$("#tree4role").tree("getSelected");
if(orgSelect!=null){
orgId = orgSelect.id;
}
var data = {
"orgId": orgId
};
$.post(
"getUsersOfOffice",
data,
function (userList) {
var len = userList.length;
console.info("len: " + len);
var str = JSON.stringify(userList);
console.info("ret: " + str);
$.each(userList, function(index, item){
console.info(item.seclevel);
});
for (let i = 0; i < userList.length; i++) {
var user = userList[i];
console.info(user.name);
}
},
"Json" //important
); //post
// $.ajax({
// url: "getUsersOfOffice",
// type: "post",
// data: data,
// dataType: "json",
// success: function (data) {
// var dataObj = data; //返回的result为json格式的数据
// $.each(dataObj, function(index, item){
// console.info(item.name);
// });
//
// console.info("ret: " + JSON.stringify(data));
// for (let i = 0; i < data.length; i++) {
// var user = data[i];
// console.info(user.name);
// }
// },
// error: function (data) {
// //alert("err");
// }
// });
}