私は現在、サンドボックスで作業していたファイルベースの実装ではなく、MongoLab から JSON オブジェクトをプルする基本的な RESTful サービスを取得しようとしています。各 JSON オブジェクトには、子配列 (先行 ID) が含まれています。
{title: 'xxyy1', course_id: '10004', semester_hours: 3, detail: 'coursename1', predecessors: ['10001']},
{title: 'xxyy2', course_id: '10005', semester_hours: 3, detail: 'coursename2', predecessors: ['10001','10003','10004']},
{title: 'xxyy3', course_id: '10006', semester_hours: 3, detail: 'coursename3', predecessors: ['10001','10003','10004']},
{title: 'xxyy4', course_id: '10007', semester_hours: 3, detail: 'coursename4', predecessors: ['10004','10006']}
これは、単に course.title、course.course_id などを ng-repeat にプルするだけで、これを angularJS に文字列化するときに完全に正常に機能します。前任者でも直接JSONとして構築することで簡単に管理できます。
<span class="predecessors">{{course.predecessors | json}}</span>
ただし、Restangular をリソース プロバイダーとして使用して MongoLab からこの同じデータセットを取得しようとすると、ビューで応答されたデータが表示されません...実際、どこにもデータが表示されません。Chrome の開発ツールを使用すると、次のように表示されます。
![Restangular レスポンス]: http://imgur.com/w8qE96K.jpg
ここで何か不足していますか?私のMongoの実装は次のとおりです。
RestangularProvider.setRestangularFields({
id: 'course_id'
});
RestangularProvider.setListTypeIsArray(false);
RestangularProvider.setResponseExtractor(function(response, operation, what, url) {
var newResponse;
if (operation === "getList" && what === "availableCourses") {
console.log(response);
newResponse = response.data.title;
newResponse.course_id = response.data.course_id;
newResponse.semester_hours = response.data.semester_hours;
newResponse.detail = response.data.detail;
newResponse.predecessors = response.data.predecessors;
} else {
newResponse = response.data;
}
return newResponse;
});