我正在尝试使用 JayData 和 Angular 显示来自 Odata Web API 控制器的数据。 我已经设法进入了在Firebug中返回数据的阶段,但是我无法将数据放入我的控制器或视图中。
这是我的应用程序.js :
var app = angular.module("app", ["localization", "ngResource", "ngRoute", "jaydata"]).
config(function ($routeProvider, $locationProvider) {
$routeProvider.
when('/Admin/Stages/List', { templateUrl: '/Content/Templates/Stages.html' }).
otherwise({ redirectTo: 'Admin/Teams/List', templateUrl: '/Content/Templates/Teams.html' });
$locationProvider.html5Mode(true); //will use html5 mode rather than hashbang where available
});
var StageListController = function ($scope, $data) {
$scope.stages = [];
$data.initService('http://lj.cloudapp.net/odata')
.then(function (lj) {
$scope.lj = lj;
$scope.stages = lj.Stages.toLiveArray();
});
};
这是我的模板:
<table class="table table-striped table-condensed table-hover">
<thead>
<th>
Stage Id
</th>
<th>
Stage Name
</th>
</thead>
<tbody>
<tr ng-repeat="stage in stages | filter:search:StageName | orderBy:'StageId'" id="stage_{{stage.id}}">
<td>{{stage.StageId}}</td>
<td>{{stage.StageName}}</td>
</tr>
</tbody>
这是我的观点:
<div data-ng-app="app">
<div class="container" ng-controller="StageListController">
<div ng-view></div>
</div>
</div>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
<script src="@Url.Content("~/Scripts/datajs-1.1.1.min.js")"></script>
<script src="@Url.Content("~/Scripts/angular.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/angular-resource.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/angular-route.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/localize.js")" type="text/javascript"></script>
<script src="http://include.jaydata.org/jaydata.js"></script>
<script src="http://include.jaydata.org/jaydatamodules/angular.js"></script>
<script src="@Url.Content("~/Scripts/angular/app.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/angular/lj.js")" type="text/javascript"></script>
代码到达控制器中的 .then,但在 $scope .stage 中未填充任何内容。 任何帮助将不胜感激。
编辑:
我已经更改了上面的以下内容以记录错误:
var StageListController = function ($scope, $data) {
$scope.stages = [];
$data.initService('http://lj.cloudapp.net/odata')
.then(function (context) {
alert(context);
$scope.context = context;
$scope.stages = context.Stages.toArray().then(function (stage) {
console.log("stage[10] is:");
console.log(stage[10]);
stage.forEach(function (p) {
console.log(stage.StageName);
});
})
.fail(function (r) {
console.log(r);
});
});
};
编辑2:
从datajs 1.1.1切换到1.0.3似乎可以解决此问题
从 datajs 1.1.1
切换到 1.0.3 似乎可以解决此问题