Benutzerschema Überprüfung eines Produkts durch den Benutzer nicht mögen:mögen und in Winkel
var UserSchema = new Schema({
review_likes : [{type:String}],
review_dislikes : [{type:String}]
});
Bewertung Schema:
var ReviewSchema = new Schema({
productID:{type: String, required: true},
numoflikes:{type:Number, required:true},
numofdislikes:{type:Number, required:true}
})
Bewertung Controller:
.controller('reviewsController', function($route, reviewsFactory, $scope, $routeParams){
var that=this;
reviewid = $routeParams.id;
productID = $routeParams.id;
likestats = false;
dislikestats = false;
/* console.log('controller',questionid)
*/ var getallReviews = function(){
reviewsFactory.getReviews(function(data){
that.reviews = data;
})
}
getallReviews();
var getProReviews = function(productID){
reviewsFactory.getProductReviews(productID, function(data){
that.proreviews = data;
})
}
getProReviews(productID);
$scope.pID=productID;
this.addReview = function(){
reviewsFactory.addReview(this.newReview, function(message){
getallReviews();
console.log(message)
that.messages = message
})
this.newReview = {};
}
var getthatReview = function(){
reviewsFactory.getthatReview(reviewid, function(data){
/* console.log('[CONTROLLER] That Question:',data);
*/ that.review = data;
})
}
getthatReview();
this.getThatReview = function(){
reviewsFactory.getthatReview(reviewid, function(data){
/* console.log('[CONTROLLER] That Question:',data);*/
reviewsFactory.checkRevLike(reviewid, function(response){
if(response == "liked"){
data.likestats = true;
}
else{
data.likestats = false;
}
angular.forEach(that.proreviews,function(e){ if(e._id == reviewid)e.likestats = data.likestats; });
angular.forEach(that.reviews,function(e){ if(e._id == reviewid)e.likestats = data.likestats; });
})
that.review = data;
})
}
this.addlikereview = function(rId){
reviewid = rId;
reviewsFactory.addRevLike(rId, function(response){
that.getThatReview();
})
}
this.removelikereview = function(rId){
reviewid = rId;
reviewsFactory.removeRevLike(rId, function(response){
that.getThatReview();
})
}
this.checklikereview = function(review){
reviewid = review._id;
reviewsFactory.checkRevLike(review._id, function(response){
if(response == "liked"){
review.likestats = true;
}
else{
review.likestats = false;
}
})
}
this.getThatReview2 = function(){
reviewsFactory.getthatReview(reviewid, function(data){
/* console.log('[CONTROLLER] That Question:',data);*/
reviewsFactory.checkRevDisLike(reviewid, function(response){
if(response == "disliked"){
data.dislikestats = true;
}
else{
data.dislikestats = false;
}
angular.forEach(that.proreviews,function(e){ if(e._id == reviewid)e.dislikestats = data.dislikestats; });
angular.forEach(that.reviews,function(e){ if(e._id == reviewid)e.dislikestats = data.dislikestats; });
})
that.review = data;
})
}
this.adddislikereview = function(rId){
reviewid = rId;
reviewsFactory.addRevDisLike(rId, function(response){
that.getThatReview2();
})
}
this.removedislikereview = function(rId){
reviewid = rId;
reviewsFactory.removeRevDisLike(rId, function(response){
that.getThatReview2();
})
}
this.checkdislikereview = function(review){
reviewid = review._id;
reviewsFactory.checkRevDisLike(review._id, function(response){
if(response == "disliked"){
review.dislikestats = true;
}
else{
review.dislikestats = false;
}
})
}
})
html:
<div ng-controller="reviewsController as revCtrl ">
<div ng-repeat="review in revCtrl.proreviews>
<div ng-init="revCtrl.checklikereview(review)"> LIKE
<div ng-if="review.likestats" ng-href="#" ng-click="revCtrl.removelikereview(review._id)" class="glyphicon glyphicon-star ">
</div>
<div ng-if="!review.likestats" ng-href="#" ng-click="revCtrl.addlikereview(review._id)" class="glyphicon glyphicon-star-empty ">
</div>
<span ng-bind="review.numoflikes"></span>
</div>
<div ng-init="revCtrl.checkdislikereview(review)"> DISLIKE
<div ng-if="review.dislikestats" ng-href="#" ng-click="revCtrl.removedislikereview(review._id)" class="glyphicon glyphicon-star ">
</div>
<div ng-if="!review.dislikestats" ng-href="#" ng-click="revCtrl.adddislikereview(review._id)" class="glyphicon glyphicon-star-empty ">
</div>
<span ng-bind="review.numofdislikes"></span>
</div>
</div>
</div>
Ich versuche, eine Überprüfung in einer Liste von Bewertungen in Fragen
ich möchte gerne/mag nicht 1 wie/Abneigung von 1 Benutzer auf eine Bewertung begrenzen
Das Problem hier ist, dass in der Anzeige in HTML, das Glyphicon erfolgreich sofort ändert, aber die Spannweite mit ng-bind = "review.numoflikes" und ng-bind = "review.numofdislikes" wird nicht sofort aktualisiert, sondern auf aktualisiert Seitenaktualisierung
Die Datenbank wird erfolgreich aktualisiert
auch, wenn Sie mir helfen könnten, nur wie oder nicht durch den Benutzer zu beschränken, wäre es großartig. Vielen Dank.
Ich bin nicht nur gehen, Ihren Code zu überprüfen, aber einige Prüfungen empfohlen: (1) sind die wie/Abneigung richtig gebunden (dh mit 'ng- Modell "im HTML) zu HTML-Elementen? (2) Ist die Funktion, die mit der DB interagiert, bekannt für '$ scope' oder' $ rootScope'? Um nur einen zu mögen/nicht zu mögen, deaktivieren Sie einfach die Tasten, sobald der Benutzer einen auswählt. – FDavidov