Handlebars: Access has been denied to resolve the property “from” because it is not an “own property” of its parent

后端 未结 11 1839
我在风中等你
我在风中等你 2020-12-05 13:27

I am using a Nodejs backend with server-side rendering using handlebars. After reading a doc array of objects from handlebars, which contains key \"content\" an

11条回答
  •  情话喂你
    2020-12-05 13:50

    Creating another new Object or Array from data returned by find() will solve the problem . See below a simple illustration

    app.get("/",(req,res)=>{
    
     let com = require('./MODELCOM')    // loading model
     let source=fs.readFileSync(__dirname+"/views/template.hbs","utf-8");
    
     com.find((err,data)=>{
        // creation new array  using map
       let wanted = data.map(doc=>{
           return {
               name:doc.name,
               _id:doc._id
            }
       })
    
        let html= handlebar.compile(source);
      fs.writeFileSync(__dirname+"/views/reciever.html",html({communities:wanted}))
        res.sendFile(__dirname+"/views/reciever.html")
    });
    

提交回复
热议问题