小编use*_*258的帖子

使用下划线模板中的函数

我试图在Underscore模板中使用一个函数,如下所示,但我收到一个错误:

未捕获的ReferenceError:未定义getProperty

以下是我正在使用的代码

var CustomerDetailView = Backbone.View.extend({
    tagName : "div",
    template: "#customer-detail-view-template",

    initialize: function() {
        _.bindAll(this, 'render');
        this.model.bind('change', this.render);
        this.initializeTemplate();
    },

    initializeTemplate: function() {
        this.template = _.template($(this.template).html());
    },

    render: function() {
        var data = this.model.toJSON();
        _.extend(data, viewHelper);
        console.log(data);
        var html = _.template($(this.template), data);
        $(this.el).html(html);
        return this;
    }
})
Run Code Online (Sandbox Code Playgroud)

和模板:

 <script type="text/template" id="customer-detail-view-template">
    <div style="height: 70px;">
        <span class="displayText">
            <p class="searchResultsAuxInfo">Full Name : <%= getProperty("full_name", null) %> </p>
            <p class="searchResultsAuxInfo">Country Code : <%= getProperty("country_code", null) %></p>
            <p class="searchResultsAuxInfo">street : <%= …
Run Code Online (Sandbox Code Playgroud)

javascript templates function backbone.js underscore.js

6
推荐指数
1
解决办法
1万
查看次数