[英]3-Way-Databinding for Single Document instead of Collection using Meteor and Angular
According to the documentation, it is possible to bind a collection to the Angular Scope with 根据文档,可以通过以下方式将集合绑定到Angular Scope:
angular.module('socially', ['angular-meteor']);
angular.module('socially').controller('PartiesListCtrl', ['$scope', function ($scope) {
$scope.parties = $meteor.collection(Parties);
}]);
}
This works really well when having a list of items I want to display. 当有我要显示的项目列表时,这确实很好用。
But now I want to edit one of those items, which means I don´t have any collection to bind, but just a single document 但是现在我要编辑其中一项,这意味着我没有要绑定的任何收藏, 而只有一个文档
angular.module('socially', ['angular-meteor']);
angular.module('socially').controller('PartiesListCtrl', ['$scope', function ($scope) {
$scope.party = $meteor.collection(Parties.findOne({my query});
}]);
}
I need a 3-Way-Binding to have changes from the client immediately saved to the database. 我需要3-Way-Binding,以将来自客户端的更改立即保存到数据库。
How is that possible for just one document? 仅一份文件怎么可能?
simply pass this into our angularjs function. 只需将其传递到我们的angularjs函数即可。
<div ng-repeat="party in parties">
<span ng-click="editparty(this)">{{party.location}}</span>
</div>
in angularjs function this
(which is now obj
) will contain the party
object. 在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});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.