javascript – 如何编辑Angular js智能表中的内容
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript – 如何编辑Angular js智能表中的内容,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2370字,纯文字阅读大概需要4分钟。
内容图文
![javascript – 如何编辑Angular js智能表中的内容](/upload/InfoBanner/zyjiaocheng/702/00d7d3512cc44f8b837ea195baf77847.jpg)
我是java脚本的新手,所以如果这看起来很基本,我必须道歉.
如何使用Angularjs在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
});
};
解决方法:
谢谢我浏览了一下并使用了http://jsfiddle.net/bonamico/cAHz7/中的代码并将其与我的代码合并.
HTML文件:
<tr ng-repeat="row in place.openHours">
<td><div contentEditable="true" ng-model="row.day">{{row.day}}</div></td>
<td><div contentEditable="true" ng-model="row.open">{{row.open}}</div></td>
<td><div contentEditable="true" ng-model="row.close">{{row.close}}</div></td>
<td>
<button type="button" ng-click="removeOpenHour(row)" class="btn btn-sm btn-danger">
<i class="glyphicon glyphicon-remove-circle">
</i>
</button>
</td>
JS档案:
myApp.directive('contenteditable', function() {
return {
require: 'ngModel',
link: function(scope, elm, attrs, ctrl) {
// view -> model
elm.bind('blur', function() {
scope.$apply(function() {
ctrl.$setViewValue(elm.html());
});
});
// model -> view
ctrl.render = function(value) {
elm.html(value);
};
elm.bind('keydown', function(event) {
console.log("keydown " + event.which);
var esc = event.which == 27,
el = event.target;
if (esc) {
console.log("esc");
ctrl.$setViewValue(elm.html());
el.blur();
event.preventDefault();
}
});
}
};
});
内容总结
以上是互联网集市为您收集整理的javascript – 如何编辑Angular js智能表中的内容全部内容,希望文章能够帮你解决javascript – 如何编辑Angular js智能表中的内容所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。