-
Notifications
You must be signed in to change notification settings - Fork 15
Open
Description
考虑到@只能单一获取数据的方式,希望能支持更加#支持调用UIView的方法。例如,这样
SomeView.prototype.uiProperties = {
name: {
value: '#getComplicatedValue'
}
};
SomeView.prototype.getComplicatedValue = function () {
if (this.model.get('some-variable') == 'some-value') {
return 100;
}
else {
return 200;
}
};这样做的好处在于可以将业务逻辑层数据与表现层数据相剥离;例如,在model中的某一业务逻辑参数取值不同,在View有N个参数需要相应变化。以往有两种方式可以完成这个逻辑:
- 在
Model中预先完成这部分参数的处理,但实际上这些参数只与表现相关,与业务逻辑无关,不应当在Model中完成。 - 在
View.enterDocument()中处理:取Model的参数,调用相应的表现逻辑函数处理,比较笨拙。
建议添加一个新的语法糖#,指定一个View的接口,在参数替换过程中直接调用。
/**
* 替换元素属性中的特殊值
*
* @param {string} value 需要处理的值
* @return {*} 处理完的值
* @public
*/
exports.replaceValue = function (value) {
if (typeof value !== 'string') {
return value;
}
if (value === '@@' || value === '**') {
return this.model;
}
var prefix = value.charAt(0);
var actualValue = value.substring(1);
if (prefix === '@' || prefix === '*') {
var path = actualValue.split('.');
var value = this.model.get(path[0]);
return path.length > 1
? getProperty(value, path.slice(1))
: value;
}
else if (prefix === '#') {
return this[actualValue]();
else {
return value;
}
};Metadata
Metadata
Assignees
Labels
No labels