【发布时间】:2015-05-13 01:47:00
【问题描述】:
在这里,我提取了一个交易列表,并将它们显示在一个启用了 show-reorder 的 ion-list 中
var ref = fb.child("/members/" + fbAuth.uid + "/accounts/" + $scope.AccountId + "/transactions/");
$scope.transactions = $firebaseArray(ref);
我有以下代码来处理排序
$scope.moveItem = function (transaction, fromIndex, toIndex) {
$scope.transactions.splice(fromIndex, 1);
$scope.transactions.splice(toIndex, 0, transaction);
};
我知道我在阅读docs here 时以错误的方式处理这个问题。但是,我无法找到对项目(在我的情况下为交易)进行排序并将这些更改保存回 Firebase 的方法。你能帮忙吗?
更新
根据下面的 Frank van Puffelen cmets,我正在添加其他信息。以以下交易为例。我从 Firebase 中提取以下交易,并按“customIndex”对其进行排序。因此,如果我在 customindex: "1" (麦当劳) 和 customindex: "2" (沃尔玛) 之间“移动” customindex: "5" (星巴克交易)
{
"accounts": {"Checking":
{payee: "McDonalds", amount: "2.35", customindex: "1"}
{payee: "Walmart", amount: "78.12", customindex: "2"}
{payee: "CapitalOne", amount: "150.00", customindex: "3"}
{payee: "FootLocker", amount: "107.54", customindex: "4"}
{payee: "Starbucks", amount: "2.88", customindex: "5"}
}}
我应该在 Firebase 中得到以下数据:
{
"accounts": {"Checking":
{payee: "McDonalds", amount: "2.35", customindex: "1"}
{payee: "Starbucks", amount: "2.88", customindex: "2"}
{payee: "Walmart", amount: "78.12", customindex: "3"}
{payee: "CapitalOne", amount: "150.00", customindex: "4"}
{payee: "FootLocker", amount: "107.54", customindex: "5"}
}}
我希望这有助于使其更清晰,并提前感谢您的帮助!
【问题讨论】:
-
您的代码中的任何内容都没有任何排序。您想按什么顺序进行交易?
标签: firebase ionic-framework angularfire