0

JSON 応答からアイテムを返そうとしていますが、構文がわかりません。応答は、カスタムの ServiceStack DTO です ("Items" と呼ばれる内部配列に注意してください)。

{"Items":[{"Id":"ABC1234","Name":"Tests-TestItem01","Desc":"Test Item 01"}]}

メソッドを持つAngularJSサービスがありますgetAll()

    function getAll() {
        return $http.get('http://servername.com/TestItems/GetAll')
            .then(getAllComplete)
            .catch(function(message) {
                exception.catcher('XHR Failed for Applications')(message);
                $location.url('/');
            });

        function getAllComplete(data, status, headers, config) {
            //return data.data[0].data.results;
            logger.info(data[0]);
            return data[0];
        }
    }

そして、このサービスを使用しようとしているコントローラーがあります:

(function () {
    'use strict';

    angular
        .module('testmodule')
        .controller('TestModule', TestModule);

    function TestModule(testItemSvc, logger) {
        var vm = this;
        vm.testItems = [];
        vm.title = "Test Items";
        vm.activate = activate;

        activate();

        function activate()
        {
            return getTestItems().then(function(){
               // Log and announce
                logger.info('Test Items loaded');
            });
        }

        function getTestItems(){
            return testItemSvc.getAll().then(function(data){
                vm.testItems = data;
                return vm.testItems;
            });
        }
    }
})();

応答が戻ってくるのはわかりますが (ここで JSON を取得しました)、項目を返す方法を特定できません。手探りのすべてがそこにありましたgetAllComplete()

編集:約束が正常に満たされたときに表示する関数と toastr ポップアップを
追加しました。activate()それは発火します。そして、私のビュー HTML の中で、私は正常に にバインドしていvm.titleます。ただし、ng-repeatループスルーを使用していますがvm.testItems、何も表示されません。

4

1 に答える 1