下面是我的一段代码
$(document).ready(function () {
// prepare the data
url="http://localhost:8080/web_test/api/user";
$.ajax({
dataType: json,
url: url,
data: "",
success: function (data, status, xhr){
var data = data.data;
var source =
{
localdata: data,
datatype: "json",
datafields:
[
{ name: 'id', type: 'string' },
{ name: 'name', type: 'string' },
{ name: 'loginName', type: 'string' },
{ name: 'password', type: 'string' },
{ name: 'mobile1', type: 'number' },
{ name: 'mobile2', type: 'number' },
{ name: 'telephone', type: 'number' },
{ name: 'email', type: 'string' },
{ name: 'gender', type: 'string' },
{ name: 'address', type: 'string' },
{ name: 'removed', type: 'number' }
]
};
}
});
}
success里面,var data = data.data 能取到data里面的数据吗
下面是本地的json数据格式,我只需要取data里面的数组就行了
{
"info" : {
"success" : true,
"code" : null,
"error" : null
},
"data" : [ {
"id" : 1,
"name" : "测试用户",
"loginName" : "test",
"password" : "test",
"mobile1" : null,
"mobile2" : null,
"telephone" : null,
"email" : null,
"gender" : null,
"address" : null,
"removed" : 0
}, {
"id" : 88,
"name" : "人生大赢家团队",
"loginName" : "lbm",
"password" : "lbm",
"mobile1" : 111,
"mobile2" : 111,
"telephone" : "111",
"email" : "111",
"gender" : null,
"address" : null,
"removed" : 0
}, {
"id" : 21,
"name" : "研发团队测试",
"loginName" : "testTWW",
"password" : "testTWW",
"mobile1" : null,
"mobile2" : null,
"telephone" : null,
"email" : null,
"gender" : null,
"address" : null,
"removed" : 0
} ]
}
这些方法是jQWidgets使用的,但是我得不到结果,应该会显示一张表格,求大神帮忙看看,万分感谢
$("#jqxgrid").jqxGrid(
{
width: 850,
source: dataAdapter,
pageable: true,
autoheight: true,
sortable: true,
altrows: true,
enabletooltips: true,
editable: true,
selectionmode: 'multiplecellsadvanced',
columns: [
{ text: 'Product Name', columngroup: 'ProductDetails', datafield: 'ProductName', width: 250 },
{ text: 'Quantity per Unit', columngroup: 'ProductDetails', datafield: 'QuantityPerUnit', cellsalign: 'right', align: 'right', width: 200 },
{ text: 'Unit Price', columngroup: 'ProductDetails', datafield: 'UnitPrice', align: 'right', cellsalign: 'right', cellsformat: 'c2', width: 200 },
{ text: 'Units In Stock', datafield: 'UnitsInStock', cellsalign: 'right', cellsrenderer: cellsrenderer, width: 100 },
{ text: 'Discontinued', columntype: 'checkbox', datafield: 'Discontinued' }
],
columngroups: [
{ text: 'Product Details', align: 'center', name: 'ProductDetails' }
]
});
将你的json数据绑定就可以了啊
或者说怎么把上面的那个json数据变成
[ {
"id" : 1,
"name" : "测试用户",
"loginName" : "test",
"password" : "test",
"mobile1" : null,
"mobile2" : null,
"telephone" : null,
"email" : null,
"gender" : null,
"address" : null,
"removed" : 0
}, {
"id" : 88,
"name" : "人生大赢家团队",
"loginName" : "lbm",
"password" : "lbm",
"mobile1" : 111,
"mobile2" : 111,
"telephone" : "111",
"email" : "111",
"gender" : null,
"address" : null,
"removed" : 0
}, {
"id" : 21,
"name" : "研发团队测试",
"loginName" : "testTWW",
"password" : "testTWW",
"mobile1" : null,
"mobile2" : null,
"telephone" : null,
"email" : null,
"gender" : null,
"address" : null,
"removed" : 0
} ]
然后我在读取这个json数据就可以了。这中间json的转变怎么写?
JavaScriptSerializer JsSerializer = new JavaScriptSerializer();
string json=JsSerializer.Serialize(list);//你的数据源
context.Response.Write(json);
你后台传到前台的数据是怎样的呢