Firebase如何按用户汇总字段

时间:2018-02-19 13:22:46

标签: javascript firebase firebase-realtime-database

我有一个带有像这样的购买对象的firebase数据库

purchase : {
    purchaseId1
    purchaseId2
    purchaseId3
}

我的每次购买都是这样的:

purchaseId1 : {
    user: userId1,
    price : 100 $
}

我使用javascript firebase api查询一些数据,我希望通过userId返回和对象的价格总和,如

purchaseOrdered : {
    {
    user: userId1,
    price : 3500 $
    }
    {
    user: userId2,
    price : 2300 $
    }
}

由于

1 个答案:

答案 0 :(得分:2)

您必须遍历对象并将价格添加到变量中。示例:

Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_UIFontDescriptor", referenced from:
  objc-class-ref in FBNotifications(FBNCardFont.o)
"_UIFontDescriptorFamilyAttribute", referenced from:
  _FBNCardFontWithNameSize in FBNotifications(FBNCardFont.o)
"_UIFontDescriptorFaceAttribute", referenced from:
  _FBNCardFontWithNameSize in FBNotifications(FBNCardFont.o)
"_UIApplicationDidReceiveMemoryWarningNotification", referenced from:
  +[ANSLifecycleEvent notificationNameMap] in Crashlytics(ANSLifecycleEvent.o)
  -[ANSAnswersController registerForApplicationLifecycleEvents] in Crashlytics(ANSAnswersController.o)
"_OBJC_CLASS_$_NSMutableParagraphStyle", referenced from:
  objc-class-ref in FBSDKCoreKit(FBSDKButton.o)
  objc-class-ref in FBSDKLoginKit(FBSDKLoginButton.o)
"_UIPasteboardNameFind", referenced from:
  ___78-[FBSDKBridgeAPIProtocolNativeV1 _JSONStringForObject:enablePasteboard:error:]_block_invoke in FBSDKCoreKit(FBSDKBridgeAPIProtocolNativeV1.o)
"_UIDeviceOrientationDidChangeNotification", referenced from:
  -[FBSDKWebDialog _addObservers] in FBSDKCoreKit(FBSDKWebDialog.o)
  -[FBSDKWebDialog _removeObservers] in FBSDKCoreKit(FBSDKWebDialog.o)
  -[CLSCrashReportingController setupStateNotifications] in Crashlytics(CLSCrashReportingController.o)
"_OBJC_CLASS_$_NSParagraphStyle", referenced from:
  objc-class-ref in FBNotifications(FBNCardTextContent.o)
"_OBJC_CLASS_$_UITableViewHeaderFooterView", referenced from:
  objc-class-ref in DigitsKit(DGTAppearance.o)
"_OBJC_METACLASS_$_UITableViewController", referenced from:
  _OBJC_METACLASS_$_DGTContactsInvitationViewController in DigitsKit(DGTContactsInvitationViewController.o)
"_OBJC_METACLASS_$_UIImageView", referenced from:
  _OBJC_METACLASS_$_DGTLogoImageView in DigitsKit(DGTLogoImageView.o)
"_OBJC_METACLASS_$_UITextView", referenced from:
  _OBJC_METACLASS_$_DGTFootnoteLabel in DigitsKit(DGTFootnoteLabel.o)
"_UIViewNoIntrinsicMetric", referenced from:
  -[DGTLogoImageView intrinsicContentSize] in DigitsKit(DGTLogoImageView.o)
  -[DGTHairlineView intrinsicContentSize] in DigitsKit(DGTHairlineView.o)
"_UIKeyboardFrameEndUserInfoKey", referenced from:
  -[DGTKeyboardAvoidingScrollView dgt_keyboardWillShow:] in DigitsKit(DGTKeyboardAvoidingScrollView.o)
"_UIAccessibilityTraitButton", referenced from:
  -[GIDSignInButton sharedInit] in GoogleSignIn(GIDSignInButton_97bfaf741496a97236fa3739518a0583.o)
"_OBJC_CLASS_$_UISearchController", referenced from:
  objc-class-ref in FirebasePhoneAuthUI(FUICountryTableViewController.o)
  objc-class-ref in DigitsKit(DGTCountryTableViewController.o)
  objc-class-ref in DigitsKit(DGTContactsInvitationViewController.o)
"_OBJC_CLASS_$_UILocalizedIndexedCollation", referenced from:
  objc-class-ref in FirebasePhoneAuthUI(FUICollationForCountries.o)
  objc-class-ref in DigitsKit(DGTCollationForCountries.o)
"_UIKeyboardAnimationDurationUserInfoKey", referenced from:
  -[FUIPhoneVerificationViewController keyboardWasShown:] in FirebasePhoneAuthUI(FUIPhoneVerificationViewController.o)
  -[FUIPhoneVerificationViewController keyboardWillBeHidden:] in FirebasePhoneAuthUI(FUIPhoneVerificationViewController.o)
  -[DGTKeyboardAvoidingScrollView dgt_keyboardWillShow:] in DigitsKit(DGTKeyboardAvoidingScrollView.o)
  -[DGTKeyboardAvoidingScrollView dgt_keyboardWillHide:] in DigitsKit(DGTKeyboardAvoidingScrollView.o)
"_UIKeyboardAnimationCurveUserInfoKey", referenced from:
  -[FUIPhoneVerificationViewController keyboardWasShown:] in FirebasePhoneAuthUI(FUIPhoneVerificationViewController.o)
  -[FUIPhoneVerificationViewController keyboardWillBeHidden:] in FirebasePhoneAuthUI(FUIPhoneVerificationViewController.o)
  -[DGTKeyboardAvoidingScrollView dgt_keyboardWillShow:] in DigitsKit(DGTKeyboardAvoidingScrollView.o)
  -[DGTKeyboardAvoidingScrollView dgt_keyboardWillHide:] in DigitsKit(DGTKeyboardAvoidingScrollView.o)
"_UIKeyboardDidShowNotification", referenced from:
  -[FUIPhoneVerificationViewController registerForKeyboardNotifications] in FirebasePhoneAuthUI(FUIPhoneVerificationViewController.o)
"_UIApplicationOpenURLOptionsAnnotationKey", referenced from:
  -[FIRAuthAppDelegateProxy initWithApplication:] in FirebaseAuth(FIRAuthAppDelegateProxy_d84ca069394368ea9e8127dbd13cc324.o)
  -[FBSDKApplicationDelegate application:openURL:options:] in FBSDKCoreKit(FBSDKApplicationDelegate.o)