在我的快速服务器上,我正在使用如下数据呈现页面:
app.get('/people/:personID', function (req, res) {
res.render("people/profile", {person: req.person });
});
Run Code Online (Sandbox Code Playgroud)
在我的profile.ejs文件中,我可以访问ejs标签中的数据,如下所示: <p><%= person.name %></p>
我无法想象如何将html标签的属性更改为存储在此对象中的值.
这不起作用:<img id="my_img" src=<%= person.picture %> alt="">
或者:$("#my_img").attr("src", <%= person.picture %>);
此外,如果有更好的方法将此文档传递到html页面并访问它,我会全神贯注(或在这种情况下是眼睛).谢谢
我从bootswatch下载了主题,我试图让用户切换主题.当切换主题时,所有bootstap css暂时消失,直到加载新主题.如何在加载css之前阻止更改或切换回默认主题,直到加载新主题为止?
index.ejs(头部)
<link rel="stylesheet" href="/external/bootstrap/css/bootstrap_yeti.min.css"
ng-if="myTheme == ''">
<link rel="stylesheet" ng-href="/external/bootstrap/css/bootstrap_{{myTheme}}.min.css"
ng-if="myTheme != ''">
Run Code Online (Sandbox Code Playgroud)
选择
<select class="form-control"
id="theme"
name="theme"
ng-model="theme"
ng-change="newTheme()">
<option value="" disabled>Select Theme</option>
<option ng-repeat="(key, val) in availableThemes" value="{{val}}">{{key}}</option>
</select>
Run Code Online (Sandbox Code Playgroud)
控制器索引
$scope.myTheme = '';
$rootScope.$watch('myTheme', function(value) {
if (value != undefined) {
$scope.myTheme = value;
}
});
Run Code Online (Sandbox Code Playgroud)
控制器供选择
$scope.availableThemes = {
Cerulean: 'cerulean',
Cosmo: 'cosmo',
Yeti: 'yeti'
};
$scope.newTheme = function() {
console.log($scope.theme);
if ($scope.theme != undefined) {
$rootScope.myTheme = $scope.theme;
}
}
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏!谢谢