所以我对这两种技术都相当陌生。我的计划是实施他们用 Backbone 制作的 Peepcode Tunes 项目(https://github.com/philipkobernik/backbone-tunes https://github.com/philipkobernik/backbone-tunes)与 MeteorJS,然后尝试使用 MeteorJS 和 AngularJS 插件来实现它。有人已经用 Angular 完成了这一切:https://github.com/angular/peepcode-tunes https://github.com/angular/peepcode-tunes
大多数事情都进展得很顺利。您可以在以下位置查看我到目前为止所拥有的内容:
只是流星:https://github.com/Jonovono/Meteor-peepcode-tunes https://github.com/Jonovono/Meteor-peepcode-tunesMeteor 和 AngularJs:https://github.com/Jonovono/Meteor-angular-peepcode-tunes https://github.com/Jonovono/Meteor-angular-peepcode-tunes
我真的很喜欢使用 Angular 并能够从视图中传递内容,例如:
ng-click="pl.add(album)">
当只使用 Meteor 时,这似乎更复杂。
然而我有一个问题。假设我想在每次添加/删除专辑时保存播放列表。这样,如果刷新页面,它仍然存在。我不知道执行此操作的最佳方法,并且当将 AngularJS 与 Meteor 一起使用时,我很困惑应该如何完成此操作。
现在,当使用 Angular 和 Meteor 时,我会执行以下操作:
$scope.Playlist = new Meteor.AngularCollection("playlist", $scope);
$scope.playlist = $scope.Playlist.findOne({});
$scope.pl.add = function(album) {
if ($scope.playlist.indexOf(album) != -1) return;
$scope.playlist.push(album);
$scope.playlist.$save();
};
然而,这似乎并没有将其保存到数据库中。但如果我要做类似的事情:
album.title = "CHANGED"
album.$save()
看起来它会将其保存到数据库中。
我确信我只是缺少一些关于 Meteor 或 AngularJS 添加的小东西。任何启发都会很棒!