dimanche 30 novembre 2014

JST templating Issue


So i have this issue where I create a marionette ItemView and i pass it a model. I than pass the model into the item view ECO JST template. The model JSON representation looks something like



{
"data": {
"user": {
"first_name": "first_name",
"last_name": "last_name"
},
"account": "23",
"key": "123"
}
}


The JST ECO template is something simple like :



<% console.log @ %> // returns entire object {data: object, escape: this.JST, safe: this.JST}
<% console.log @data %> // returns data object


In the JavaScript debugger. If i set a break point onto the jst template (@data.user //this.data.user) it returns the users object but when i try to inspect the user object inside the jst file i get a undefined



<% console.log @data.user %> // returns undefined


Any suggestions?


Thanks UPDATED::: ADDING Classes and Views and ECO templates



//list_controller.coffee
#user_data contains response from server.
showApiSubmit:(options) ->
apiSubmitBtn = @getSubmitButton(options)
apiSubmitBtn.on "api:submit:clicked",(model) ->
user_data = App.reqres.request("api:get:userbyid")
user = new Backbone.Model //without this the @data object doesnt show up in template at all
user.model = user_data
console.log("user_data", user_data)
data = List.Controller.getApiPopUpModal(user)
List.Controller.layout.apiResponse.show data
@layout.apiSubmit.show apiSubmitBtn

getApiPopUpModal:(model) ->
new List.PopUpModal
model: model.model

// ListView
class List.PopUpModal extends App.Views.ItemView
template: "/templates/_api_popup_modal"

//_api_popup_modal.jst.eco
<%- console.log "popup", @ %> // shows data object with user object inside
<%- console.log "popup", @data.user %> // shows undefined
<%- console.log "popup args", arguments %>
<div id ="popUpDiv">

</div>


hope this helps me find out why i cant access the user data. Thanks





Aucun commentaire:

Enregistrer un commentaire