I have partial button
that looks like:
.button button.custom_button(type='button', value='', onclick=#{functionName}) #{functionName}
And I render partials with help of res.renderPartials
function which comes from npm install express-partial
.
And I want to render it on user request. So I have controller method like:
var express = require('express');
var router = express.Router();
router.get('/buttons', function(req, res) {
var funcs = ['func1();', 'func2();', 'func3()', .... ]; // where funcs.length > 15
res.renderPartials({
// PROBLEM #1: how to make this in a loop
// PROBLEM #2: why do it returns only the func[28] rendering result
'partials/button': {functionName: funcs[0]},
'partials/button': {functionName: funcs[1]},
..........
'partials/button': {functionName: funcs[28]},
});
});
Question: how to render all button partials at once? Mean pass array to res.renderPartials
and avoid encountering each button separated by comma.
PS I supposed that's possible because in Jade template we can do this:
- each video in videos
!=partial('partials/video', {title:video.title, artist:video.artist})
Example is taken from here
I though in my case we can use embedded partials, like
buttons.jade
- each func in #{functions}
!=partial('partials/button', {functionName:func})
button.jade
.button button.custom_button(type='button', value='', onclick=#{functionName}) #{functionName}
router
var express = require('express');
var router = express.Router();
router.get('/buttons', function(req, res) {
res.renderPartials({
'partials/buttons': {functions: ['func1();', 'func2();', 'func3()', .... ]}
});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.