【问题标题】:MVC Model List to AngularJsAngularJs 的 MVC 模型列表
【发布时间】:2015-07-06 11:30:10
【问题描述】:

我确实有一个具有 studentID、firstName、LastName、PhotoURL 和列表的模型,我尝试将模型绑定到这样的 angularJs

var app = angular.module('StudentApp', []);
app.controller('StudentCtrl', function ($scope) {
    $scope.model = @Html.Raw(Json.Encode(Model));
    console.log($scope.model);
});

当我控制台.log 它向我展示了这样的

Object {StudentID: 0, FirstName: null, LastName: null, PhotoURL: null, _StudentList: Array[5]}

FirstName: null LastName: null PhotoURL: null StudentID: 0 _StudentList:Array[5]
0: Object 
    FirstName: "John"
    LastName: "Doe"
    PhotoURL: "phone-wallpaper-1920x1200.jpg"
    StudentID: 5 
    _StudentList: null__proto__: 
1: Object 
    FirstName: "Ahri"
    LastName: "Fox"
    PhotoURL: "ahri-wallpaper-1920x1200.jpg"
    StudentID: 6 
    _StudentList: null__proto__: 
Object2: 
Object3: 
Object4: 

表示我得到了五个学生的数据,现在我想用 ng-repeat 打印这五个学生的数据

我试过这样

<table class="table" ng-app="StudentApp">
<tbody ng-controller="StudentCtrl">
    <tr>
        <th>Key</th>
        <th>First Name</th>
        <th>Last Name</th>
        <th>Profile picture</th>
        <th>Options</th>
    </tr>
    <tr ng-repeat="student in $scope.model._StudentList">
        <td></td>
        <td>{{student.FirstName}}</td>
        <td>{{student.LastName}}</td>
    </tr>
}
</tbody>

但它不起作用

无论我在哪里控制台日志都可以正常工作

console.log($scope.model._StudentList[0].FirstName);
console.log($scope.model._StudentList[0].LastName);

打印 John Doe

【问题讨论】:

    标签: html asp.net-mvc angularjs


    【解决方案1】:

    您不应该在 ng-repeat 中使用 $scope,只需将其设为 model._StudentList 即可。

    【讨论】:

      猜你喜欢
      • 2017-05-15
      • 1970-01-01
      • 1970-01-01
      • 2011-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多