2013-08-08 28 views
5

Aşağıdaki denetleyici, bir tablo ve form içeren bir görünümü besler. tablonun ilgili parçasıdır: Bir satır tıklandığındaAngularFire, Firebase dosyasını güncelleştirmiyor bazen

<tr ng-repeat="obj in tab.col | filter:filterObj" ng-click="select(obj)" ng-class="isSelected(obj)">

, form (onun modeli tab.obj olan) obj ayrıntılarını görüntüler ve düzenleyebilirsiniz. Tablo, form formlarında kullanıcı bir nesneyi değiştirdiğinde, tablo uygun bir şekilde alır, ancak firebase herhangi bir güncelleştirme almaz, ancak yeni nesnelerin eklemelerini almaz (bu bir array.push (obj) ile yapılır).

define(['app'], function(app) { 
app.controller('LinksCtrl',['$scope', '$filter', '$http','angularFire','angularFireAuth', function($scope,$filter,$http, angularFire, angularFireAuth) { 
$scope.links = {}; 
$scope.tabs = []; 

var url = "https://<url>.firebaseio.com/links"; 
angularFireAuth.initialize(url, {scope: $scope, name: "user", path: "/"}); 
var promise = angularFire(url, $scope, 'links', {}) 

$scope.select = function (item) { 
    for(i in $scope.tabs) { 
    var tab = $scope.tabs[i]; 
    if (tab.active) { 
     tab.obj = item; 
     if (tab.obj.selected) { 
     tab.obj.selected = ! tab.obj.selected; 
     } else { 
     tab.obj.selected = true; 
     // $scope.$apply(); 
     } 
    } 
    } 
}; 

$scope.isSelected = function(obj) { 
    if (obj.selected && obj.selected === true) { 
    return "active"; 
    } 
    return ""; 
} 


promise.then(function() { 

    $scope.tabs.push({ 
    title: 'links', 
    disabled: false, 
    active: false, 
    col: $scope.links.open, //this is an array of objects 
    obj: {} 
    }); 

    $scope.tabs[0].active = true; 

    for(i in $scope.tabs) { 
    var tab = $scope.tabs[i]; 
    tab.actions = app.actions(); 

    // app.actions returns an array with more objects like the following doing CRUD and other basic stuff 
    tab.actions.push({ 
     name: 'Delete link', 
     icon: 'icon-minus', 
     cond: function(tab) { if ('selected' in tab.obj) { return tab.obj.selected}; return false; }, 
     func: function(tab) { 
     // splice tab.col or whatever modification 
     } 
    }); 
    }; 
}); 
    }]); 

}); 

Bu çalışma gibi bir şeyi nasıl yapabilirim? koleksiyonlar aracılığıyla manuel senkronizasyona geçmeli mi? const.log ile hata ayıklama, nesnesinin, kodun tüm aşamalarında olması gereken (prototip, kod kodu, vb.) nesnelere sahip olduğunu gösterir, bu yalnızca firebase'in güncellemeleri almamasıdır.

Güncelleme:

Ben çalışan bir çözümümüz var. Görünüşe göre, bağlayıcı bir problem ya da bunun gibi bir şey, ama neler olduğundan emin değilim. . ?. Bu açısal benim kullanımı olabilir

controller scope ------ 

    // get the firebase data and store it in 
    var promise = angularFire(url, $scope, 'links', {}) 

    // build the tabs structure, where tabs[i].col = $scope.links.i 

    // build actions for each tab 

    // create an empty tabs[i].obj to use in the form model 

ng-repeat scope ------- 

    // iterate over the tab structure 
    <tab ng-repeat="tab in tabs" heading="{{tab.title}}" active="tab.active" disabled="tab.disabled"> 

ng-repeat scope -------- 

    // Iterate over the elements, so we can select one, and edit it, updating firebase 
    // If we iterate over tab.col, firebase does not get the updates, but If we iterate over 
    // the original $scope.links variable, it works as expected 

    <tr ng-repeat="obj in links[tab.title] | filter:filterObj | orderBy: 'date':true" ng-click="select(obj)" ng-class="isSelected(obj)"> 
+0

Bu, görüşte iki iç içe geçmiş yinelenmenin kapsam dansı göz önüne alındığında bir bağlanma sorunu gibi görünüyor. Ancak tüm öğeler nesnelerdir ve çalışmalıdır: -? [bağlantı] (https://github.com/angular/angular.js/wiki/Understanding-Scopes) –

+0

Bir çözüm bulma grat! Çözümünüzü aşağıdaki bir cevaba kopyalar mısınız? Gelecekteki araştırmacıların bulmasını kolaylaştırır :) – mimming

cevap

1

Ben: - sekmelerin atama [i] .col = $ scope.links.i i = 'açık' bu durumda (suçlu benziyor işe yarayan bir çözüm Benim tarafımdan bağlayıcı bir problem gibi görünüyor. [i] .col = $ scope.links.i sekmelerinin atanması suçlu gibi görünüyor (bu durumda i = 'open': - ?. açısal benim kullanımı olabilir.

çözeltisi yerine sekme kullanılarak ait [i] .col, kullanım $ scope.links, yani, bir $ kapsamı değişkeni için bir referans yerine $ kapsamı değişken kullanın.

controller scope ------ 

    // get the firebase data and store it in 
    var promise = angularFire(url, $scope, 'links', {}) 

    // build the tabs structure, where tabs[i].col = $scope.links.i 

    // build actions for each tab 

    // create an empty tabs[i].obj to use in the form model 

ng-repeat scope ------- 

    // iterate over the tab structure 
    <tab ng-repeat="tab in tabs" heading="{{tab.title}}" active="tab.active" disabled="tab.disabled"> 

ng-repeat scope -------- 

    // Iterate over the elements, so we can select one, and edit it, updating firebase 
    // If we iterate over tab.col, firebase does not get the updates, but If we iterate over 
    // the original $scope.links variable, it works as expected 

    <tr ng-repeat="obj in links[tab.title] | filter:filterObj | orderBy: 'date':true" ng-click="select(obj)" ng-class="isSelected(obj)"> 
İlgili konular