我试图在这篇文章中使用加藤提供的答案:here但是不理解在angularfire中使用优先级的概念。在angularfire API文档中有一个非常简短的优先级,但没有示例。
到目前为止,这是我项目的Plnkr:http://plnkr.co/edit/A8lDKbNvhcSzbWVrysVm
//controller
angular.module('app').controller('MainCtrl', function($firebase, $scope) {
var ref = new Firebase('https://plnkr.firebaseio.com').startAt().endAt();
var list = $firebase(ref).$asArray();
$scope.list = list;
console.log(list);
var last = null;
$scope.priorityChanged = function(priority) {
var current = moment(priority).startOf('day');
var changed = last === null || !last.isSame(current);
last = current;
return changed;
};
$scope.getDayName = function($priority) {
return moment($priority).format('dddd');
};
$scope.addTask = function(newTask) {
list.$add({
title: newTask.title,
timestamp: Firebase.ServerValue.TIMESTAMP
});
};
});
//view
<form ng-submit="addTask(task); task.title=null">
<input placeholder="Add Task" ng-model="task.title"/>
</form>
<li ng-repeat="item in list" ng-init="changed = priorityChanged(item.$priority)">
<h3 ng-show="changed">{{getDayName(item.$priority)}}</h3>
{{item | json}}
</li>
答案 0 :(得分:1)
问题是plnkr在其包管理器中具有8.0版本的angularfire。它在最新版本中运行得很好。
$scope.addTask = function(newTask) {
list.$add({
title: newTask.title,
$priority: 3
});
};