如何在firebase中更新字典,同时用angularjs添加时间戳
How to update a dictionary within firebase while also add a time stamp with angularjs?
下面的代码更新列表中的firebase字典,并为该更新创建时间戳,但复杂的是,我需要将firebase对象转换为html
中的数组JSFiddle: http://jsfiddle.net/chrisguzman/b84up41y/
HTML<section ng-app ="myapp" ng-controller="MyController">
<div ng-repeat= "(id,item) in data">
<form ng-submit="AddComment(id)">
<input ng-model="item.comment"></input>
</form>
</div>
</section>
JAVASCRIPT angular.module("myapp", ["firebase"])
.controller('MyController',function MyController($scope, $firebase) {
var ref = new Firebase("https://helloworldtest.firebaseio.com");
$scope.data = $firebase(ref);
$scope.AddComment = function (id) {
$scope.data[id].DateLastModified = Date.now();
$scope.data.$save(id)}
});
但是当我添加|orderByPriority将firebase对象转换为数组时,我可以像这样应用过滤器
<form ng-submit="AddComment(id) |orderByPriority">
它不再工作
但是,当我删除下列组件时,它确实可以更新列表中的字典,这是我需要的组件。
$scope.data[id].DateLastModified = Date.now();
根据firebase
orderByPriority过滤器是由AngularFire提供的,用来把$firebase返回的对象转换成一个数组。数组中的对象按优先级排序(在Firebase中定义)。此外,数组中的每个对象都有一个定义在其上的$id属性,它将对应于该对象的键名。
但是,id似乎返回0而不是示例中的id i show
直接传递商品的id
:
<div ng-repeat= "item in data|orderByPriority">
<form ng-submit="AddComment(item.$id)">
<input ng-model="item.comment"></input>
</form>
</div>
注意,在ng-repeat
中,我只在data
中寻找item
。
相关文章:
- 如何每10.6秒从时间戳增加+1
- 使用AngularJS从时间戳中获取工作日
- 将时间戳转换为java中的ISO860,
- Javascript Unix时间戳转换
- JavaScript JSON关联对象键和值都作为日期时间戳
- 时间戳与mongoskin如何
- 用时间戳获取两个不同日期之间的时间差
- JavaScript到PHP的时间戳失败,增加了大约一个半月的时间
- 转换unix时间戳转换
- 带有unix时间戳的d3.js平分线
- 当转换为Python日期时间时,Node的时间戳落后3分钟
- 如何检索AMD的XHR响应代码(+时间戳)'大型Dojo
- javascript时间戳插入字符串变量
- Moment.js unix时间戳,以分钟为单位显示以前的时间
- Angularjs:带日期助手的格式化UTC时间的时间戳
- 处理日期时间时间戳javascript(angularjs)和mongo的滑块
- 将 AngularJS 中的时间戳格式化为自定义要求
- 如何在firebase中更新字典,同时用angularjs添加时间戳
- 如何在AngularJs中使用moment将Unix时间戳转换为GMT (IST)格式的日期
- 我如何要求AngularJS为时间戳格式化本地时间?