Saturday 10 June 2017

How to get specific data from large json object into Jade mixin

This is the json from my sever:

data = {"id":393, "state":"mississippi", "lat":null, "lng":null, "title":"someTitle", "country":null};

I then pass that through a Jade temple like so: res.render('editUpload', {fromServer:data});

Then in my Jade template I have this:

var data = !{fromServer};
console.log(data.address);

Which correctly prints mississippi

However, I'm trying to get my mixins to use that data

Mixin:

mixin textBoxMixin(name, label, value)
    div(style="display:flex; width:100%;")
        span.label #{label}
        input(type="text", name="#{name}", value="#{value}")

Then I use that like this:

+textBoxMixin("title", "Title", fromServer)

which fills in the text box with the entire json "{"id":393, "state":"mississippi", "lat":null, "lng":null, "title":"someTitle", "country":null}" so I go and try this:

+textBoxMixin("title", "Title", fromServer.title)

it prints "undefined".

How do I get this mixin to accept what should just be fromServer.title?

I've tried JSON.stringify(fromServer), data.address (which obviously doesn't work because data is undefined during the rendering of the page). I know that I could go back to my server and parse out all the json there and pass each item as an individual item, but that would be a giant pain since my json is actually much larger than what I've posted here.



via Glen Pierce

No comments:

Post a Comment