Skip to content

Commit

Permalink
添加initConnectedChildren方法
Browse files Browse the repository at this point in the history
Fix #585
  • Loading branch information
otakustay committed Jun 12, 2016
1 parent f052027 commit ffe6790
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
31 changes: 31 additions & 0 deletions src/helper/children.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

/**
* 销毁所有子控件
*/
Expand Down
1 change: 0 additions & 1 deletion src/helper/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ define(
* @protected
*/
helper.initializeTemplateEngineExtension = function () {
var me = this;
u.each(
FILTERS,
function (filter, name) {
Expand Down

0 comments on commit ffe6790

Please sign in to comment.