我在表行上使用ng-repeat,其中包含从服务器检索的JSON数组中的数据.我的目标是在服务器上添加,删除或修改项目时自动更新列表,而不会影响未修改的项目.在最终实现中,这些表行还将包含双向绑定<input>和<select>元素,以将更新发送回服务器.<select>元素中的一些可用选项也将使用来自另一个列表的ng-repeat指令生成,这些指令也可能会更改.
到目前为止,每当新阵列来自服务器(当前每两秒轮询一次)时,整个ng-repeat列表将被删除并重新生成.这是有问题的,因为它干扰文本选择,即使用户当前正在编辑它们也会破坏输入字段,并且可能比必要的运行速度慢很多.
我已经编写了其他使用jQuery和DOM操作执行我想要的Web应用程序,但代码最终变得非常毛茸茸并且开发非常耗时.我希望使用AngularJS和数据绑定来完成这个代码和时间的一小部分.
所以这里有一个问题:是否可以通过这种方式更新支持数组,但只修改与实际更改的项目/属性相对应的DOM元素?
这是一个最小的测试用例,它使用计时器中的硬编码数组模拟周期性轮询(请参见http://jsfiddle.net/DWrmP/).请注意,由于要删除并重新创建元素,因此每500毫秒清除一次文本选择.
<body ng-app="myApp">
<table ng-controller="MyController">
<tr ng-repeat="item in items | orderBy:'id'">
<td>{{item.id}}</td>
<td>{{item.data}}</td>
</tr>
</table>
</body>
Run Code Online (Sandbox Code Playgroud)
angular.module('myApp', []).controller(
'MyController', [
'$scope', '$timeout',
function($scope, $timeout) {
$scope.items = [
{ id: 0, data: 'Zero' }
];
function setData() {
$scope.items = [
{ id: 1, data: 'One' },
{ id: 2, data: 'Two' },
{ id: 5, data: 'Five' },
{ id: 4, data: 'Four' }, …Run Code Online (Sandbox Code Playgroud) 我正在使用Rails 4应用程序,该应用程序需要创建大量对象以响应来自其他系统的事件.当我调用我的某个模型时,我在主键列上遇到非常频繁的ActiveRecord::RecordNotUnique错误(由此引起PG::UniqueViolation)create!.
我在SO上找到了其他答案,建议救出异常并致电retry:
begin
TableName.create!(data: 'here')
rescue ActiveRecord::RecordNotUnique => e
if e.message.include? '_pkey' # Only retry primary key violations
log.warn "Retrying creation: #{e}"
retry
else
raise
end
end
Run Code Online (Sandbox Code Playgroud)
虽然这似乎帮助,我仍然得到吨的ActiveRecord::RecordNotUnique误差,对于已经存在于数据库(日志条目略)顺序ID:
WARN -- Retrying creation: PG::UniqueViolation: DETAIL: Key (id)=(3067) already exists.
WARN -- Retrying creation: PG::UniqueViolation: DETAIL: Key (id)=(3068) already exists.
WARN -- Retrying creation: PG::UniqueViolation: DETAIL: Key (id)=(3069) already exists.
WARN -- Retrying creation: PG::UniqueViolation: DETAIL: Key (id)=(3070) already …Run Code Online (Sandbox Code Playgroud) 是否可以使用一组 C 库或系统调用来删除 POSIX 或至少在 Linux 上的所有用户权限?请注意,我不是在问如何删除root特权,这就是所有其他 StackOverflow 搜索结果似乎都在询问和回答的问题。
I want the same effect as switching to user nobody, but stronger if possible. That is, I want my C application to do the following:
root, and without the setuid file permission bitactiverecord ×1
angularjs ×1
c ×1
javascript ×1
linux ×1
postgresql ×1
privileges ×1
ruby ×1
sandbox ×1
security ×1
sql ×1