我有3个表Collection
,Subcollection
和Products
。
Collection
表ID在Subcollection
和Products
表中用作forgien键。 Sub .... table id用作Products
表中的外键。
现在我正在尝试使用角度js从Collection
获取集合列表。但是我没有在视图中得到任何东西。在控制台中错误显示。当我点击错误时,它会转到错误:
ngRepeat:愚弄
中继器中的重复键。
但是当我尝试获取另一个表的数据时,它没有任何关系,所以我想知道如何从表中获取与另一个表与外键的关系。我也在$index
尝试追踪,但那不起作用
public JsonResult getcolldata()
{
var lst = eShoppingEntitiesContetxt.Collections.Where(x => x.IsActive == true).ToList();
var data = JsonConvert.SerializeObject(lst, new JsonSerializerSettings
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
});
return Json(data, JsonRequestBehavior.AllowGet);
}

<!-- AppModule -->
var app = angular.module("StudentApp", []);
<!-- Service -->
app.service("EmployeeService", function ($http) {
this.getEmployee = function () {
return $http.get("/User/getcolldata");
};
});
<!-- Controller -->
app.controller("StudentController", function ($scope, EmployeeService) {
GetAllEmployee();
function GetAllEmployee() {
$scope.name = "Sample";
var getAllEmployee = EmployeeService.getEmployee();
getAllEmployee.then(function (emp) {
$scope.employees = emp.data;
}, function () {
alert('Data not found');
});
}
});
&#13;
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="~/Scripts/AppModule.js"></script>
<script src="~/Scripts/Controller.js"></script>
<script src="~/Scripts/Services.js"></script>
<div ng-app="StudentApp" class="container">
<br/>
<br/>
<input type="text" placeholder="Search Student" ng-model="searchStudent" />
<br />
<div ng-controller="StudentController">
<table class="table">
<tr ng-repeat="r in employees | filter : searchStudent" >
<td>{{ r.Col_Title }}</td>
</tr>
</table>
</div>
</div>
&#13;