【问题标题】:Updating firebaseAsArray item and save更新 firebaseAsArray 项目并保存
【发布时间】:2015-09-22 18:04:12
【问题描述】:

您好,我正在使用 firebase 和 angularfire 作为帐户网络应用程序的后端, 处理此功能的设计逻辑有问题
在 ng 重复表中获取对象 $scope 将对象转换为表单 - 并允许编辑 将更新的 $scope 保存到对象(// 可能是对象键或 $id

    $scope.records = $firebaseArray(data_records);
    // updating value
$scope.updateValue = {};
$scope.key = null;
$scope.showDoUpdate = false;

$scope.openUpdate = function(record, key) {
    $scope.showDoUpdate =  true;
    $scope.updateValue.customerCode = record.customerCode;
    $scope.updateValue.credit = record.credit;
    $scope.updateValue.debit = record.debit;
    $scope.updateValue.property_no = record.property_no;
    $scope.updateValue.arrears = record.arrears;
    $scope.updateValue.closingBlance = record.closingBlance;

    $scope.key = key;
};

$scope.closeUpdate = function() {
    $scope.records[key] = $scope.updateValue;
    $scope.records.$save();
    $scope.updateValue = {};
    $scope.key = null;
    $scope.showDoUpdate = false;
};

在我的html中

 <tbody>
        <tr ng-repeat="(key,record) in records">
            <td>{{records.customerCode}}</td>
            <td>{{records.property_no}}</td>
       <td>
           <button class="btn" ng-    click="openUpdate(key,record)">edit</button>
        </td>


 <!--form ...........
         <button ng-click="closeUpdate()" class="btn ">Save</button>

【问题讨论】:

    标签: angularjs firebase


    【解决方案1】:

    $index 会帮助你。尝试类似...

    ng-repeat="rec in records"
    

    然后在你的 ng-click 中:

    ng-click="openUpdate(records[$index].record, records[$index].key)"
    

    哪个会调用...

    $scope.openUpdate = function(record, key) {
        $scope.key = key;
        //other work
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-28
      • 2017-07-27
      • 1970-01-01
      • 2022-01-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多