diff --git a/src/helper/children.js b/src/helper/children.js index 1f2caa5f..b87d4129 100644 --- a/src/helper/children.js +++ b/src/helper/children.js @@ -33,6 +33,37 @@ define( return ui.init(wrap, options); }; + /** + * 批量初始化自有子控件 + * + * 该方法与`intiChildren`的不同在于,会使用一个特殊的`valueReplacer`, + * 在子控件的HTML中的`foo="@bar.x.y"`会等效于父控件的`get('bar').x.x` + * + * @param {HTMLElement} [wrap] 容器DOM元素,默认为主元素 + * @param {Object} [options] init参数 + * @param {Object} [options.properties] 属性集合,通过id映射 + * @return {Array} 子控件数组 + */ + helper.initConnectedChildren = function (wrap, options) { + var control = this.control; + var valueReplacer = function (value) { + if (value.charAt(0) === '@') { + var path = value.substring(1).split('.'); + var propertyName = path.shift(); + var result = u.reduce( + path, + function (value, property) { + return value[property]; + }, + control.get(propertyName) + ); + return result; + } + }; + options = u.extend({valueReplacer: valueReplacer}, options); + return this.initChildren(wrap, options); + }; + /** * 销毁所有子控件 */ diff --git a/src/helper/template.js b/src/helper/template.js index ee6190fe..02444c85 100644 --- a/src/helper/template.js +++ b/src/helper/template.js @@ -62,7 +62,6 @@ define( * @protected */ helper.initializeTemplateEngineExtension = function () { - var me = this; u.each( FILTERS, function (filter, name) {