我正在尝试将json对象绑定到kendo移动列表视图,但listview绑定json数组中的所有字符,包括括号和引号。
function loadtypes() {
$("#pull-to-refresh-listview").empty();
var murl = "/Home/getTypes/";
$.ajax({
url: murl,
cache: false,
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: 'json',
success: function (data) {
console.log(JSON.stringify(data.TypesViewModel));
var dataSource = new kendo.data.DataSource({ data: JSON.stringify(data.TypesViewModel) });
$("#pull-to-refresh-listview").kendoMobileListView({
dataSource: dataSource,
//template: "#: type_name #",
filterable: true,
virtualViewSize: 50 // needed setting, since local data virtualization does not use paging
});
return dataSource;
},
error: function (reponse) {
return '{"error":"Error"}';
}
});
}
Controller:
public ActionResult AddTypes(TypeModel model)
{
rep = new GroceryRepository();
rep.AddType(model);
return Json("success", JsonRequestBehavior.AllowGet);
}
JSON:
[{ “ID”:0, “TYPE_NAME”: “饮料”},{ “ID”:0, “TYPE_NAME”: “肉”},{ “ID”:0, “TYPE_NAME”: “测试” },{ “ID”:0, “TYPE_NAME”: “TEST2”},{ “ID”:0, “TYPE_NAME”: “TEST3”},{ “ID”:0, “TYPE_NAME”: “TEST4”}, { “ID”:0, “TYPE_NAME”: “TEST5”},{ “ID”:0, “TYPE_NAME”: “TEST7”},{ “ID”:0, “TYPE_NAME”: “test8”},{” ID “:0,” TYPE_NAME “:” TYPE6" }]
答案 0 :(得分:0)
这是因为您正在将JSON转换为包含JSON.stringify
的字符串。