-1

我正在使用 w2ui 网格,模板列生成如下:

{ field: 'TableCards', caption: 'Table cards', size: '10%', sortable: true ,
            render:function(record, index, column_index) {
                let html = '';
                if (record.TableCards) {
                       record.TableCards.forEach(function(card) {
                         html += `<div class="card-holder" style="width: 12%; display: inline-block; padding: 0.5%;">
                                    <div class="poker-card blah" poker-card data-value="${card.value}"
                                        data-color="${card.color}"
                                        data-suit="&${card.suit};"
                                        style="width: 30px;height: 30px">
                                    </div>
                                </div>`;
                    });
                }
                return html;
            } 
        },

如您所见,扑克卡是一个自定义属性。并且它不会在网格中呈现。还有其他方法吗?

4

1 回答 1

0

您可以TemplatingEngine.enhance()在动态 HTML 上使用 。

有关完整示例,请参阅本文:http: //ilikekillnerds.com/2016/01/enhancing-at-will-using-aurelias-templating-engine-enhance-api/


重要提示:根据您的自定义属性的实现方式,您可能需要调用 View 的生命周期钩子,例如.attached()

这发生在我身上,当使用图书馆aurelia-material时,他们的属性mdl

查看实现的源代码MDLCustomAttribute现在查看以下代码片段,它显示了我需要做什么才能使mdl属性与动态 HTML 一起正常工作:

private _enhanceElements = (elems) => {

    for (let elem of elems) {

        let elemView = this._templEngine.enhance({ element: elem, bindingContext: this});

        //we will now call the View's lifecycle hooks to ensure proper behaviors...
        elemView.bind(this);
        elemView.attached();

        //if we wouldn't do this, for example MDL attribute wouldn't work, because it listens to .attached()
        //see https://github.com/redpelicans/aurelia-material/blob/5d3129344e50c0fb6c71ea671973dcceea14c685/src/mdl.js#L107
    }
}
于 2016-11-16T11:48:14.097 回答