0

ASP.NETWebAPIで実装されたサービスポイントがあります。IEnumerableに埋め込まれたdtoのリストを返しますHttpResponseMessage

ただし、バックボーンコレクションフェッチを介して実装されたクライアントコードは、常にエラーになります。エラーメソッド内で、パラメータを渡して監視しているときに、コレクションがプロパティの下に表示されていることがわかりResponseTextます。

IEnumerable<dto>でラップせずに直接通過しますがHttpResponseMessage、問題なく動作します。

私の質問:正しい方法は何ですか?ResponseTextバックボーンコレクションにプロパティ内の内容を参照させるにはどうすればよいですか?

いろいろと試して、単一のモデルをフェッチし、フェッチメソッドをオーバーライドしようとしています。

categories = new Categories({ url: 'http://localhost:6685/category' });

$.when(categories.fetch())
    .then(
        function() {
               app.init({ 'categories': categories, 'cart': cart });

               });

これは私にあいまいなエラーを与え続けます。それから私が切り替えたとき

categories.fetch({
            success: function() {... },
            error: function(err) {

                console.log(err);
            }
        });

カテゴリリストの内部を確認できます。プロパティ名はresponsetextです。

var Categories = Backbone.Collection.extend({

    model: Category,

    initialize: function (options) {
        this.url = options.url;
    },

    parse:function (response) {
        return response.categories;
    },

サーバ側

HttpResponseMessage<IEnumerable<category>> httpresponse = null;

 var response= _catalogueservice.getcategories();

            if (response.success)
            {

                httpresponse =  new HttpResponseMessage<IEnumerable<category>>(response.categories, response.categories.Count()>0?HttpStatusCode.Found:HttpStatusCode.NotFound);
            }
            else
            {
                httpresponse = new HttpResponseMessage<IEnumerable<category>>( HttpStatusCode.NotFound);

            }

        return httpresponse;

Fiddlerの下で、JSONが返されていることがわかります。

4

1 に答える 1

1

常にサービスをシンプルに保ちます。ほとんどのAPIユーザーが、利便性のためにデータの周りに別のラッパーを使用する必要があることに気付いたとき、あなたは悪夢に陥っています。とにかくそれを脇に置いておくのはあなたがしなければならないすべてです

var todos = Backbone.Collection.extend({
url:"todoapi/gettodos",
parse:function(response){
   return response.Todos
}
});

あなたの応答を考慮に入れると、以下のようになります

{Error:"NULL",Todos:[{Id:1,Todo:"Welcome"},{Id:2,Todo:"Eat"...}]}
于 2012-05-17T09:45:15.337 に答える