4

好的,我正在使用 angularFire-seed 存储库来测试如何连接 angularjs+firebase+python-firebase 库。

我的目标是从 python 脚本向 firebase 添加内容并将其显示在网页上。

这是一个控制器:

    ......
    angular.module('myApp.controllers', [])
       .controller('MyCtrl1', ['$scope', 'FBURL', 'angularFire', function($scope,
       FBURL, angularFire) {
       angularFire(FBURL+'/syncedValue', $scope, 'syncedValue', '');
       }])
    ......

这是视图:

    ......
    <h4>{{syncedValue}}</h4>
    <input ng-model="syncedValue" type="text" />
    ......

一切正常:

在此处输入图像描述


firebase 调试器

有用!当我在网页上输入内容时,它会显示在 firebase 调试器中。

现在我在 python 中这样做:

   from firebase import Firebase
   f = Firebase("https://xxxxx.firebaseio.com/syncedValue")
   r = f.update({"syncedValue": "3433"})

这使得一个孩子到syncedValue:

firebase 调试器

   r = f.push({"syncedValue": "3433"})

这使得一个孩子有一个 uid:

在此处输入图像描述

但我只想简单地更新syncedValue键的值而不添加任何孩子,就像这样......

Prollie angularjs 中的一些东西我不明白。

4

2 回答 2

3

我知道了!

   from firebase import Firebase
   f = Firebase("https://xxxxx.firebaseio.com/syncedValue")
   r = f.update({"syncedValue": "3433"})**strong text**

该代码更新了 syncedValue 的一个孩子,所以....

我只是简单地在控制器中创建了一个孩子:

  ......
angular.module('myApp.controllers', [])
   .controller('MyCtrl1', ['$scope', 'FBURL', 'angularFire', function($scope,
   FBURL, angularFire) {
   angularFire(FBURL+'/syncedValue/1', $scope, 'syncedValue', '');
   }])
......

在此处输入图像描述

于 2013-08-25T02:24:43.820 回答
0

Python 中有一个非常简单的库,可用于与 Firebase 一起使用,语法不那么混乱。你应该检查一下 https://github.com/andela-cnnadi/pyfirebase

对于这种情况,您可能想做这样的事情

from pyfirebase import Firebase
f = Firebase('https://xxxxx.firebaseio.com/')
ref = firebase.ref('syncedValue')
ref.set(3433)

然后,您可以随时使用相同的语法继续更新此引用:

 ref.set("newValue")
于 2016-07-02T23:44:08.777 回答