```onChange: function (newValue, oldValue) {
$.ajax({
type: 'post',
url: "/DMS/ProductionData/GetListByEquTy",
data: { newValue: newValue },
async: false,
success: function (data) {
//该如何取值
}
});
``` public List<DMS_EquStopTypeModel> GetListByEquTy(string newValue)
{
List<DMS_EquStopTypeModel> list = new List<DMS_EquStopTypeModel>();
MyCommonHelp mycommonHelp = new MyCommonHelp();
StringBuilder sql = new StringBuilder();
sql.AppendFormat(@"select Id,EquStop_Desc from DMS_EquStop
where EquStop_Type = '{0}'", newValue);
DataTable dt = DBHelp.GetDataTable(sql.ToString());
list = mycommonHelp.ConvertToList<DMS_EquStopTypeModel>(dt);
return list;
}
$.each(data, function (i, item) {
var id=item.Id;
var desc=item.EquStop_Desc
}
);
这样试试
补充
后台方法改成
public ActionResult GetListByEquTy(string newValue)
{
List<DMS_EquStopTypeModel> list = new List<DMS_EquStopTypeModel>();
MyCommonHelp mycommonHelp = new MyCommonHelp();
StringBuilder sql = new StringBuilder();
sql.AppendFormat(@"select Id,EquStop_Desc from DMS_EquStop
where EquStop_Type = '{0}'", newValue);
DataTable dt = DBHelp.GetDataTable(sql.ToString());
list = mycommonHelp.ConvertToList<DMS_EquStopTypeModel>(dt);
return Json(list, JsonRequestBehavior.AllowGet);
}
首先后台返回的list要转成json的格式 , 前台直接for循环 data就行 然后第一行就是 date[0].列名 就可以了
Map<String, Object> dataMap = new HashMap<String, Object>();
dataMap.put("returnObj", list);//与前台交互的数据集
String jsonString = JSONObject.toJSONString(dataMap);//转化为json格式的字符串
HttpServletResponse response = getResponse();
response.setContentType("text/html;charset=UTF-8");
response.setCharacterEncoding("UTF-8");
try {
response.getWriter().print(jsonString);
} catch (IOException e) {
e.printStackTrace();
}
//前台通过data.returnObj取得数据集
//例如你想取得第一个对象中的某一个属性
//eg:data.returnObj[0].属性名
以上仅为个人观点,有疏忽的地方,望指正,谢谢。