我對Java腳本來說很新,所以如果這看起來很基本,我必須道歉。如何在Angular js中編輯內容智能表
如何使用Angularjs編輯智能表中的行表?新的智能表似乎沒有教程。我想創建一個簡單的表格,讓用戶輸入特定地點的營業時間。
我已經創建了可以在表上添加和刪除行的按鈕,但是當我添加contenteditable =「true」時,更新對象時沒有任何更改會持續。我知道contenteditable是一個獨立於智能表的特定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
});
};
我認爲你需要做的角度使用CONTENTEDITABLE多一點的工作。它直接改變了dom,你需要捕捉這些變化,以便Angular知道它們。 https://github.com/akatov/angular-contenteditable/blob/master/angular-contenteditable.js – elpddev 2015-02-11 18:08:22