使用流星和Angular为单个文档提供3- way数据绑定,而不是集合

3-Way-Databinding for Single Document instead of Collection using Meteor and Angular

本文关键字:数据绑定 way 集合 流星 Angular 文档 单个      更新时间:2023-09-26

根据文档,可以使用

将集合绑定到Angular作用域
 angular.module('socially', ['angular-meteor']);
  angular.module('socially').controller('PartiesListCtrl', ['$scope', function ($scope) {
    $scope.parties = $meteor.collection(Parties);
  }]);
}

当我有一个想要显示的项目列表时,这非常有效。

但现在我想编辑其中一个项目,这意味着我没有任何集合要绑定,而只是一个文档

 angular.module('socially', ['angular-meteor']);
  angular.module('socially').controller('PartiesListCtrl', ['$scope', function ($scope) {
    $scope.party = $meteor.collection(Parties.findOne({my query});
  }]);
}

我需要一个3-Way-Binding从客户端立即保存到数据库的更改。

怎么可能只有一个文档?

把它传递给我们的angularjs函数。

<div ng-repeat="party in parties">
      <span ng-click="editparty(this)">{{party.location}}</span>
 </div>
angularjs函数this(现在是obj)中的

将包含party对象。

$scope.editparty = function(obj){
    obj.party.location = "England"; //edit party object
    //pass to our database...
    obj.party = $meteor.collection(Parties.findOne({my query});
});