Kendo UI の作業を始めたばかりです。MVC Web アプリケーション プロジェクト用の Kendo UI を作成し、ユーザーのリストをグリッドに表示するビューを作成しました。ユーザーのデータは、作成した Azure Web サービスから取得されます。
私が抱えている問題は、無効なラベルがあるという構文エラーがあることです。これは Firebug がキャッチしている json です
{
"Meta": {
"Method": "GetUsuarios",
"Status": "ok"
},
"Response": [
{
"ApellidoM": "TestInfo1",
"ApellidoP": "TestInfo1",
"CreatedDateTime": "/Date(1357763187027-0600)/",
"Nombre": "TestInfo1",
"Password": "TestInfo1",
"UpdatedDateTime": "/Date(1357763187027-0600)/",
"UserName": "TestInfo1",
"UsuarioId": 1
},
{
"ApellidoM": "TestInfo2",
"ApellidoP": "TestInfo2",
"CreatedDateTime": "/Date(1357863418857-0600)/",
"Nombre": "TestInfo2",
"Password": "TestInfo2",
"UpdatedDateTime": "/Date(1357863418857-0600)/",
"UserName": "TestInfo2",
"UsuarioId": 2
}
]
}
JSONLint.com でテストしましたが、これは有効な json 文字列です。これは、DataSource を作成してグリッドを埋める JavaScript 関数です。
$(function () {
var ds = new kendo.data.DataSource({
transport: {
read: {
url: "http://127.0.0.1:81/SismosService.svc/usuario/index",
dataType: "jsonp"
}
},
schema: {
data: "Response"
},
});
$("#usuariosGrid").kendoGrid({
columns: ["Nombre", "ApellidoP", "ApellidoM"],
dataSource: ds
});
});
そして、これは私の見解です:
<!DOCTYPE html>
<html>
<head >
<link href="<%: Url.Content("~/Content/kendo/2012.3.1114/kendo.common.min.css")%>" rel="stylesheet" type="text/css" />
<link href="<%: Url.Content("~/Content/kendo/2012.3.1114/kendo.default.min.css")%>" rel="stylesheet" type="text/css" />
<title><%: ViewBag.GestionTitle %></title>
</head>
<body>
<h1><%: ViewBag.GestionTitle %></h1>
<div id="usuariosGrid"></div>
<button id="addUsuario" type="button" class="k-input"><%: ViewBag.Agregar %></button>
<script src="<%: Url.Content("~/Scripts/jquery-1.7.1.min.js")%>"></script>
<script src="<%: Url.Content("~/Scripts/kendo/2012.3.1114/kendo.web.min.js")%>"></script>
<script src="<%: Url.Content("~/Scripts/usuario/usuario.js")%>"></script>
</body>
</html>
ご覧のとおり、私がやろうとしていることは非常に単純ですが、なぜ失敗するのでしょうか? 私の Web サービスは、私が作成した ResponseObject 内のユーザーのリストを送信します。クラスは次のようになります。
[DataContract]
public class ResponseObject<T>
{
public ResponseObject(T[] Response, MetaObject Meta)
{
this.Response = Response;
this.Meta = Meta;
}
[DataMember]
public T[] Response { get; set; }
[DataMember]
public MetaObject Meta { get; set; }
}
Meta は、Web サービスが成長し、新しい情報をクライアントに送信する必要があるときに情報を追加するために作成した別のクラスです。
これは、ユーザーを取得するためのメソッドが私のインターフェースでどのように定義されているかです:
[WebGet(UriTemplate = "/usuario/index",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare)]
ResponseObject<Usuarios> GetUsuarios();
このエラーは何を受け取っていますか? ユーザーへの送信方法が間違っていますか?