0

I'm attempting to use Handlebars templates with Backbone w/ Marionette. Maybe I'm biting off more frameworks than I can chew right now but if I can work through this last issue then I will have all the pieces worked out.

So what I have right now is Marionette Layout being rendered with a Handlebars template. The static code in the template is rendering so I am assuming that at least the basic wiring is correct. I added some debug code to the success callback of my model's fetch call, like this:

success: function(model, response, options) {
    $.log(response);
}

What I get for the response is something like this (data sanitized but you get the idea):

{
    "adminLoginId": 0,
    "deviceHashAVInfos": [
        {
            "foo": "bar"
        }
    ],
    "orgId": 0,
    "timeTaken": 39,
    "numHits": 1,
    "message": "success",
    "success": true
}

So, it seems to be getting data back from the service. But for the life of me, I can't seem to get the syntax correct to read the data. Just trying to access the orgId, for example, I've tried: {{orgId}},{{this.orgId}},{{data.orgId}},{{response.orgId}},{{attributes.orgId}}. I've even tried to set the orgId as a default value in the model.

4

1 回答 1

0

您不应该使用 Marionette 布局来显示模型(它用于显示区域中的视图)。相反,请尝试使用项目视图并将模型作为参数传递,就像您可以在此处看到的那样:https ://github.com/davidsulc/marionette-gentle-introduction/blob/master/assets/js/apps/contacts/show /show_controller.js#L14

您可以在此处了解有关使用基本视图显示模型的更多信息:http: //samples.leanpub.com/marionette-gentle-introduction-sample.pdf

于 2013-08-31T09:26:49.727 回答