I am struggling to pass parameters via fastify to my page, as its just passing object Object as a string instead of my actual object.
This might just be me being a little stupid as im not exactly sure how fastify works, nor the formatting of the HBS files, as this was a project discontinued by the previous developer and I decided to pick it up to add missing features to it!
EDIT: after trying a couple different methods to attempt to get this to work, ive found this only happens in the script tags, so is there a different way to import this information to be used in scripts?
Here are some snippets of my code that may be useful:
index.js
/** * Our home page route * * Returns src/pages/index.hbs with data built into it */ fastify.get("/", function(request, reply) { const colors = require("./src/colors.json"); let params = { seo: seo, colors: colors }; reply.view("/src/pages/index.hbs", params); }); index.hbs
<form class="color-search" method="post"> <label for="sim"> <select name="sim" id="sim"> </select> </label> <label for="box"> <select name="box" id="box"> </select> </label> </form> <script> let box = $('select[name=box]'); let sim = $('select[name=sim]'); sim.append('<option>Choose one</option>'); console.log("test") console.log({{colors}}) $.each({{colors}}, function(key, entry) { sim.append($('<option></option>').attr('value', entry).text(entry.name)); }); colors.json
{ "Sim A": { "Box A": { "name": "", "connects": ["Box B"] }, "Box B": { "name": "", "connects": ["Box A", "Box C"] } }, "Sim B": { "Box C": { "name": "", "connects": ["Box B", "Box D"] }, "Box D": { "name": "", "connects": ["Box C", "Box E"] }, "Box E": { "name": "", "connects": ["Box D"] }, } And lastly what is seen in the developer console
let box = $('select[name=box]'); let sim = $('select[name=sim]'); sim.append('<option>Choose one</option>'); console.log("test") console.log([object Object]) // this is whats wrong $.each([object Object], function(key, entry) { sim.append($('<option></option>').attr('value', entry).text(entry.name)); }); any ideas why colors is being passed as object Object instead of the actual object?