我对Java Script还比较新,如果这看起来很基础,请谅解。
如何在Angularjs的Smart-Table中编辑行表?似乎没有新的Smart-Table教程。我想创建一个简单的表单让用户输入一个特定地点的营业时间。
我已经创建了可以添加和删除表中行的按钮,但是当我使用contenteditable="true"时,在更新对象时没有任何更改被保存。我知道contenteditable是独立于smart-table的特定HTML5参数,但我不明白如何更新数据或如何检索更新后的数据。
数据通过mean.js路由从angularjs控制器中检索。
<div class="controls">
<table st-table="place.openHours" class="table table-striped">
<thead>
<tr>
<th>Day</th>
<th>Opening Time</th>
<th>Closing Time</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="row in place.openHours" contenteditable="true" >
<td>{{row.day}}</td>
<td>{{row.open}}</td>
<td>{{row.close}}</td>
<button type="button" ng-click="removeOpenHour(row)" class="btn btn-sm btn-danger">
<i class="glyphicon glyphicon-remove-circle">
</i>
</button>
</tr>
</tbody>
</table>
<button type="button" ng-click="addOpenHour(row)" class="btn btn-sm btn-success">
<i class="glyphicon glyphicon-plus">
</i> Add new Row
</button>
</div>
在 JavaScript 中:
$scope.removeOpenHour = function removeOpenHour(row) {
var index = $scope.place.openHours.indexOf(row);
if (index !== -1) {
$scope.rowCollection.splice(index, 1);
}
}
$scope.addOpenHour = function addOpenHour() {
$scope.place.openHours.push(
{
day: 'Monday',
open: 540,
close: 1080
});
};