Element: The case of the [Feature Request] form name=a.b.c format

Created on 22 Mar 2018  ·  1Comment  ·  Source: ElemeFE/element

Existing Component

Yes

Component Name

element-ui/lib/utils/util.js

Description

如果表单的name=a.b.c,el-form上绑定的数据源目前必须是{a:{b:{c:1}}}这种格式,但是我现在的数据源model={'a.b.c': 1} 这种就不支持了。希望能支持,如:先判断数据源里是否有name等于'a.b.c' 名字对应的值,没有的情况下,在依次遍历name取值。 下面这个方法。是否可以支持下

function getPropByPath(obj, path, strict) {
var tempObj = obj;
path = path.replace(/[(\w )]/g, '.$1');
path = path.replace(/^./, '');

var keyArr = path.split('.');
var i = 0;
for (var len = keyArr.length; i < len - 1; i) {
if (!tempObj && !strict) break;
var key = keyArr[i];
if (key in tempObj) {
tempObj = tempObj[key];
} else {
if (strict) {
throw new Error('please transfer a valid prop path to form item!');
}
break;
}
}
return {
o: tempObj,
k: keyArr[i],
v: tempObj ? tempObj[keyArr[i]] : null
};
};

>All comments

Sorry, we have no plan to support this.

Was this page helpful?
0 / 5 - 0 ratings