Commit bb5a4d96 authored by 覃振观's avatar 覃振观 👶

JS 属性映射

parent 55069726
...@@ -43,6 +43,58 @@ function loadDataTest() { ...@@ -43,6 +43,58 @@ function loadDataTest() {
inputEventListener(); inputEventListener();
}); });
} }
// 数据映射配置
var dataMapping = {
"productDetail": [
"factoryName"
, { "productLayout": "productLayout" }
],
"ProductLooked": [
"productLength"
, "productWidth"
]
}
// 构建映射关系。
function mapping(dataMapping, rawData) {
let entitySet = Object.entries(dataMapping);
entitySet.tryForEach((entity, index) => {
let beanName = entity[0];
let propertyNames = entity[1];
let entityData = isExist(rawData, beanName) ? rawData[beanName] : throw {};
propertyNames.tryForEach((item, index) => {
if(typeof item === "string") {
let value = isExist(entityData, item, item) ? entityData[item] : throw {};
dataMapping.item = beanName;
console.log(item);
return;
}
if(item instanceof Object) {
let entry = Object.entries(item);
let property = entry[0];
let value = isExist(entityData, property, property) ? entityData[property] : throw {};
let alias = entry[1];
dataMapping.alias = { beanName: property };
}
})
})
}
Array.prototype.tryForEach = function (callback, thisArg) {
try {
this.forEach(callback, thisArg);
} catch { }
}
function isExist(obj, property) { this.isExist(bj, property, 'rawData') }
function isExist(obj, property, objName) {
if(!obj[property]) {
console.error('No data for name of ' + entity[0] + ' in ' + objName + ' !');
return false;
}
return true;
}
function faceGrid(elId, data) { function faceGrid(elId, data) {
var toolbarOptions = UICtrl.getDefaultToolbarOptions({ var toolbarOptions = UICtrl.getDefaultToolbarOptions({
...@@ -126,23 +178,37 @@ function inputEventListener() { ...@@ -126,23 +178,37 @@ function inputEventListener() {
}); });
} }
function getHashCode(str,caseSensitive){ // 用于判断字符串是否更改。
if(!caseSensitive){ function getHashCode(str) {
getHashCode(getHashCode, true);
}
function getHashCode (str, caseSensitive) {
if(!caseSensitive) {
str = str.toLowerCase(); str = str.toLowerCase();
} }
// 1315423911=b'1001110011001111100011010100111' if (str.length === 0) return 0;
var hash = 1315423911,i,ch; var len = str.length;
for (i = str.length - 1; i >= 0; i--) { var hash = 1315423911, i, ch;
for (i = len - 1; i >= 0; i--) {
ch = str.charCodeAt(i); ch = str.charCodeAt(i);
hash ^= ((hash << 5) + ch + (hash >> 2)); hash = (hash << 5) + ch + (hash >> 2);
}
var hash2 = hash ^ (hash << 7) ^ (hash >> 6);
var hash3 = hash2 ^ (hash2 << 1) ^ (hash2 >> 13);
if (len < 50) {
var hash4 = this.getHashCode(str + str + str, caseSensitive);
return (hash ^ hash2 ^ hash3 ^ hash4) & 0x7FFFFFFF ;
} else {
return (hash ^ hash2 ^ hash3 >> 3 ) & 0x7FFFFFFF;
} }
var hash2 = hash ^ (hash << 10) ^ (hash >> 6);
var str2 = str + str + str;
var hash3 = this.getHashCode(str2, caseSensitive);
return (hash & 0x7FFFFFFF) ^ hash2 ^ hash3;
} }
// if(!isExist(rawData, entity[0])) {
// throw {};
// }
// let entityData = rawData[entity[0]];
// checkbox: true, // checkbox: true,
// enabledSort: false, // enabledSort: false,
// autoAddRowByKeydown:false, // autoAddRowByKeydown:false,
......
...@@ -88,6 +88,7 @@ public class ProductApplicationImpl implements ProductApplication { ...@@ -88,6 +88,7 @@ public class ProductApplicationImpl implements ProductApplication {
entitys.add(publishedConfRepository.findByProductId(strProductId)); entitys.add(publishedConfRepository.findByProductId(strProductId));
entitys.add(productDetail); entitys.add(productDetail);
HashMap<String, Object> listMaps = new HashMap<>(100); HashMap<String, Object> listMaps = new HashMap<>(100);
resultMap.putAll(assembleResultOfForm(entitys)); resultMap.putAll(assembleResultOfForm(entitys));
listMaps.put("loss", loss); listMaps.put("loss", loss);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment