将字符串与jade节点js中的动态数据连接起来

时间:2012-12-11 16:26:47

标签: node.js express pug

任何人都知道如何将字符串与动态数据连接起来,以便将其传递到表单模板中?

我的控制器是:

exports.edit = function(req, res) {
    var id = req.params.id;
    Product.findOne({id: id}, function(err, doc){
        if (err) {
            res.send("There is no product with this " + id + "!")
        } else {
            res.partial('products/edit', {title: "Edit", product: doc});
        }
    });
};

我的产品/ edit.jade文件是:

-if (product != null)
    h2 Edit
    form.form-edit(method="post", action="products/#{product.id}", name="form-edit")
        !=partial("inc/form-edit", { type: "Edit", image: "../img/" + #{product.image}})
                                                  // Doesn't work, i can pass only strings to my form template

和我的inc / form-edit.jade文件是:

.....
    input#bt-prod-edit.btn.btn-primary(type="button", value="Parcourir")
    img(src="#{image}")
    div.align-center
      input.bt-cancel.btn(type="button", name="bt-cancel", value="Annuler")
      input#bt-prod-edit.btn.btn-primary(type="submit", name="bt-prod-edit", value="#{type}")

所以如果我这样做

!=partial("inc/form-edit", { type: "Edit", image: "image_path"})

工作正常,但如果我尝试传递任何动态数据,我会收到一条错误消息:意外的令牌ILLEGAL

有谁知道为什么?

非常感谢

1 个答案:

答案 0 :(得分:1)

而不是:

!=partial("inc/form-edit", { type: "Edit", image: "../img/" + #{product.image}})

尝试:

!=partial("inc/form-edit", { type: "Edit", image: "../img/" + product.image})