1

如何在 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')
});
4

0 回答 0