如何使angularfire发送NG-电网的onblur变化自动火力地堡? [英] how to make angularfire send ng-grid onBlur changes to firebase automatically?

查看:153
本文介绍了如何使angularfire发送NG-电网的onblur变化自动火力地堡?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是从这里的后续问题:<一href=\"http://stackoverflow.com/questions/20929801/how-to-create-3-way-data-binding-between-angularfire-0-5-0-and-latest-ng-grid\">How创建3路数据angularFire 0.5.0和最新NG网?哪里之间加藤很好的结合提供了一个解决方案:

This is a followup question from here: How to create 3 way data binding between angularFire 0.5.0 and latest ng-grid? where Kato nicely provided a solution:

var app = angular.module('app', ['firebase', 'ngGrid']);
var fb = new Firebase('https://nggrid-example.firebaseio-demo.com/');

app.controller('ctrl', function($firebase, $scope, orderByPriorityFilter) {
    $scope.data = $firebase(fb);
    $scope.myData = $firebase(fb);
    $scope.$watchCollection('data', function() {
       $scope.myData = orderByPriorityFilter($scope.data); 
    });
    $scope.gridOptions = { data: 'myData',enableCellEditOnFocus: true };
});

然而,这种解决方案将很好地数据到我的NG-格,但如果我编辑任何单元格,更改将不会自动应用到火力点。

However, this solution puts data nicely into my ng-grid, but if I edit any of the cells, changes are not automatically applied to firebase.

我已经尝试了各种方法,但没有人似乎工作:

I have tried various ways, but none of them seem to work :

$scope.$on('ngGridEventEndCellEdit',function(value){
                    $scope.data.$set(value);
                });

不。

我也尝试angularFire事件处理程序,如。在$(变)

I have also tried angularFire event handlers such as .$on("change")

表我创造将通过实时多个用户进行编辑。

Tables I am creating will be edited by multiple users in real time.

加藤解决方案很好地转换火力对象为数组,但我还需要找到一种方法如何编辑值NG-电网转换为对象,所以我可以存储他们火力的飞行。

Kato solution nicely converts firebase objects into arrays, but then I also need to find a way how to convert edited values in ng-grid to objects so I can store them in firebase on the fly.

如果我想补充 NG-模糊=updateEntity(COL,行)我的 editableCellTemplate:,然后我补充一点:

if I add ng-blur="updateEntity(col, row)" to my editableCellTemplate: and then I add this :

$scope.updateEntity = function(col,row){
                    console.log(row.entity);
                    console.log(col.field);
                };

控制台注销完美,但我也得到这个错误:

console logs out perfectly, but I also get this error:

错误:Firebase.set失败:第一个参数包含在财产targetScope无效键($ ID)。钥匙必须是非空字符串,不能包含。,#,$,/,[或]

P.S。我得到这个错误只有当我有这个问题,以及:

P.S. I get this error only if I have this as well:

$scope.$on('ngGridEventEndCellEdit',function(value){
                    $scope.data.$set(value);
                });

如果我没有这一块,再没有什么要保存到火力点(或至少尝试过)。

If I dont have this piece, then nothing is being saved to firebase (or atleast tried).

推荐答案

我终于找到了解决办法!

I finally found the solution !!

所有这一切都需要做的是将这样的: NG-模糊=updateEntity(COL,行) editableCellTemplate:,然后这样的:

All that is needed to be done is adding this : ng-blur="updateEntity(col, row)" to editableCellTemplate: and then this:

$scope.updateEntity = function(col,row){
                    $scope.data.$save(row.entity.$id);
                };

现在这样: $ scope.data $集; 将无法正常工作,因为它会取代你的火力数据库的整体搭配。(row.entity的$ id)。编号(这样一个数,例如0)。使用它之前,所以总是测试一下吧! :)

Now this: $scope.data.$set(row.entity.$id); will not work, because it will replace THE WHOLE OF YOUR FIREBASE DATABASE with id (so a number, for example "0"). So always test it before using it! :)

Tadaaaa! 3路数据绑定!

Tadaaaa ! 3 way data binding!

这篇关于如何使angularfire发送NG-电网的onblur变化自动火力地堡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆