Ember.js从另一个调用一个绑定助手

时间:2013-10-30 15:55:15

标签: javascript ember.js

如何在ember.js中调用另一个有界助手?

我希望能够使用以下车把模板。这有可能吗?

{{#each row in content}}
<tr>
    {{#each column in columns}}
        <td>{{object _view row column}}</td>
    {{/each}}
</tr>
{{/each}}

我试过这样的事情:

Ember.Handlebars.registerBoundHelper('property', function (object, property) {
    if(property && property.name) {
        return Ember.get(object, property.name);
    }

    return null;
});

Ember.Handlebars.registerBoundHelper('object', function (view, object, property) {
    if (property && property.name) {
        if (property.formatter) {
            return property.formatter.call(property.name, {
                data: {
                    view: view,
                },
                types: ["ID"],
                hash: {},
                object: object,
                property: property,
            });
        }

        return Ember.get(object, property.name);
    }

    return null;
});

属性按以下方式定义:

Ember.Object.create({
    name: "message",
    title: "Message",
    formatter: Ember.Handlebars.helpers.property
});

对象是:

的实例
App.Log = DS.Model.extend({
    module: DS.attr('string'),
    message: DS.attr('string'),
    user: DS.belongsTo('App.User')
});

0 个答案:

没有答案