【问题标题】:Firebase + Angularjs + PythonFirebase + Angularjs + Python
【发布时间】:2013-08-27 19:32:49
【问题描述】:

好的,我正在使用 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 调试器中。

现在我在 python 中这样做:

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

这使得一个孩子同步值:

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

这让孩子有了一个 uid:

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

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

【问题讨论】:

    标签: javascript python model-view-controller angularjs firebase


    【解决方案1】:

    我明白了!

       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', '');
       }])
    ......
    

    【讨论】:

      【解决方案2】:

      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")
      

      【讨论】:

        猜你喜欢
        • 2013-09-06
        • 1970-01-01
        • 1970-01-01
        • 2012-10-15
        • 2015-05-01
        • 2017-03-27
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多