【发布时间】:2014-12-04 18:20:55
【问题描述】:
如何通过 ng-click 将新行推送到表中? 这就是我目前所拥有的。信息在一个数组中。
我的数组看起来像这样。
$scope.workflows = [{
Id: 1,
Name: "Workflow Page 1",
Description: "Describe Workflow",
Steps: [{
Id: 1,
Name: "name me",
Description: "describe me",
Action: "do something",
Obj: "whats the goal",
AdditionalInfo: "anything else",
}, {
Id: 2,
Name: "name me",
Description: "describe me",
Action: "do something",
Obj: "whats the goal",
AdditionalInfo: "anything else",
},
]},
}, ];
这是我要添加到数组中的内容,以及我如何使用范围来尝试添加它。
$scope.addStep = function(newStep) {
$scope.newStep = [{
Id: 0,
Name: "Step on THIS!",
Description: "I dare ya!",
Action: "STOMP!",
Obj: "A Rock",
AdditionalInfo: "I am bleeding...",
}]
$scope.workflows.push(newStep);
alert("test :" + "Its GON WORK");
};
然后在 HTML 中,我使用 ng-click 来激活 newStep 函数,希望它在我的表中创建一个新行。
<div class="text" ng-click="addStep(newStep)"> + Click to Add a New Step</div>
谢谢!
【问题讨论】:
-
使用
console.log或 Angular 的 $log 进行调试,而不是使用alert进行调试。
标签: javascript arrays angularjs object push