1

angularjs 的新手,所以我不确定如何最好地表达这个问题,所以这可能是重复的。我有一个表格,我想用一个标签和一些复选框来填充。每行代表一个测试指标,带有两个表示“通过”或“失败”的复选框

function ListController($scope) {
    $scope.items = [
        {name: 'Feature X', flash: false, html: false},
        {name: 'Feature Y', flash: false, html: false}
    ];
}

我已经正确填充了表格,但我不确定如何动态创建此表格?我希望能够在选择新测试时提交这些数据并创建一个新表。我现在可以看到调用此函数的唯一方法是初始化文档,我看不到如何传入任何附加值以根据测试更改“项目”节点。小提琴下面:

http://jsfiddle.net/3Lcue/

4

1 回答 1

1

您可以使用$resource从服务器提交/检索数据:

app = angular.module("Test", ["ngResource"])

function ListController($scope, $resource) {
    var Test = $resource("/tests/:id", {id: "@id"});
    $scope.items = Test.query()

    $scope.addTest: function() {
        $scope.items.push($scope.newTest)
        $scope.newTest = {}
    }
}

然后在您的视图中newTest.name使用.newTest.flashnewTest.htmlng-model

于 2013-03-27T23:06:12.283 回答