如果用户是admin,我正在尝试显示图像,否则,显示通用图像。
问题是,用户是管理员,我相信我正在插入正确的代码,但输出无效。我尝试了许多不同的方法,但希望有人能帮助我。
这是我的模式
var UserSchema = new mongoose.Schema({
username: {type: String, unique: true, required: true},
password: String,
isAdmin:{type: Boolean, default: false},
firstname: String,
lastname: String,
email: {type: String, unique: true, required: true},
resetPasswordToken: String,
resetPasswordExpires: Date,
});
这是我的JavaScript代码
<% if(comment.author.username == "Anonymous"){ %>
<img src="https://gamepedia.cursecdn.com/cod_esports_gamepedia_en/archive/1/1d/20180401162348%21Unknown_Infobox_Image_-_Player.png" alt="" style="border-radius:50px; margin-right:20px;">
<% }else if (comment.author.isAdmin){ %>
<img src="https://scontent-dfw5-1.xx.fbcdn.net/v/t31.0-8/15937293_702429746602294_1257383716040040171_o.png?_nc_cat=111&_nc_ht=scontent-dfw5-1.xx&oh=f943ddf0358410cf6f5cd4296d0f099e&oe=5CE576F0" alt="" style="border-radius:50px; margin-right:20px;">
<% }else{ %>
<img src="https://upload.wikimedia.org/wikipedia/commons/c/cd/Still_Life_with_Bible_-_My_Dream.jpg" alt="" style="border-radius:50px; margin-right:20px;">
<% } %>
结果是我的管理员图像不会显示,但会显示else标签中的图像