Node.js Express Js-使用车把局部视图
我正在学习express,并尝试使用它的局部视图 App.js 家用把手 main.handlebar默认布局 weather.handlebar局部视图 现在,当我运行应用程序时,我看不到页面上填充的数据。我下面的这个例子来自一本名为《使用Node和Express进行Web开发》的书Node.js Express Js-使用车把局部视图,node.js,express,handlebars.js,Node.js,Express,Handlebars.js,我正在学习express,并尝试使用它的局部视图 App.js 家用把手 main.handlebar默认布局 weather.handlebar局部视图 现在,当我运行应用程序时,我看不到页面上填充的数据。我下面的这个例子来自一本名为《使用Node和Express进行Web开发》的书 我使用的节点版本是v0.10.36,对于车把,我使用的是express3车把插件。您可能需要预填充数据。i、 例如,跑步 ... getWeatherData() app.use(function(req, re
我使用的节点版本是v0.10.36,对于车把,我使用的是express3车把插件。您可能需要预填充数据。i、 例如,跑步
...
getWeatherData()
app.use(function(req, res, next){...
在函数之后填充值。我想这本书就是这么写的我以前用过
将res.locals.partials.weather的名称更改为res.locals.partials.weatherData
在呈现主页之前,应填充res.locals.partials.weatherData,移动代码:
app.use(function(req, res, next){
if(!res.locals.partials)
res.locals.partials = {};
res.locals.partials.weather = getWeatherData();
next();
})
在下列日期之前:
app.get('/', function(req, res){
res.render('home');
});
使用
app.usefunctionreq,res,app.get'/'之前的下一个{..}您能详细说明一下您的问题吗?
<div class="weatherWidget">
<label>Data received for: {{partials.weather.locations.length}} cities</label>
{{#each partials.weather.locations}}
<div class="location">
<h3>{{name}}</h3>
<a href="{{forecastUrl}}">
<img src="{{iconUrl}}" alt="{{weather}}">
{{weather}}, {{temp}}
</a>
</div>
{{/each}}
<small>Source: <a href="http://wunderground.com">Weather Underground</a></small>
</div>
...
getWeatherData()
app.use(function(req, res, next){...
app.use(function(req, res, next){
if(!res.locals.partials)
res.locals.partials = {};
res.locals.partials.weather = getWeatherData();
next();
})
app.get('/', function(req, res){
res.render('home');
});