丰富了,支持更多语义
This commit is contained in:
parent
e36cf430cf
commit
ff0fcc8492
|
|
@ -569,11 +569,16 @@ export default class TreeStore extends CascadeStore {
|
|||
case '$length': {
|
||||
// json中的数组长度查询
|
||||
const length = value;
|
||||
assert(typeof length === 'number');
|
||||
return (row) => {
|
||||
const data = path ? get(row, path) : row;
|
||||
assert(data instanceof Array, '$length operator can only used on array attribute');
|
||||
return data.length === length;
|
||||
if (typeof length === 'number') {
|
||||
return data.length === length;
|
||||
}
|
||||
else {
|
||||
const op = Object.keys(length)[0];
|
||||
return this.translatePredicate(entity, length, op, length[op], option)(data);
|
||||
}
|
||||
};
|
||||
}
|
||||
default: {
|
||||
|
|
|
|||
|
|
@ -571,11 +571,16 @@ class TreeStore extends CascadeStore_1.CascadeStore {
|
|||
case '$length': {
|
||||
// json中的数组长度查询
|
||||
const length = value;
|
||||
(0, assert_1.assert)(typeof length === 'number');
|
||||
return (row) => {
|
||||
const data = path ? (0, lodash_1.get)(row, path) : row;
|
||||
(0, assert_1.assert)(data instanceof Array, '$length operator can only used on array attribute');
|
||||
return data.length === length;
|
||||
if (typeof length === 'number') {
|
||||
return data.length === length;
|
||||
}
|
||||
else {
|
||||
const op = Object.keys(length)[0];
|
||||
return this.translatePredicate(entity, length, op, length[op], option)(data);
|
||||
}
|
||||
};
|
||||
}
|
||||
default: {
|
||||
|
|
|
|||
|
|
@ -710,11 +710,16 @@ export default class TreeStore<ED extends EntityDict & BaseEntityDict> extends C
|
|||
case '$length': {
|
||||
// json中的数组长度查询
|
||||
const length = value;
|
||||
assert (typeof length === 'number');
|
||||
return (row) => {
|
||||
const data = path ? get(row, path) : row;
|
||||
assert(data instanceof Array, '$length operator can only used on array attribute');
|
||||
return data.length === length;
|
||||
if (typeof length === 'number') {
|
||||
return data.length === length;
|
||||
}
|
||||
else {
|
||||
const op = Object.keys(length)[0];
|
||||
return this.translatePredicate(entity, length, op, length[op], option)(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
default: {
|
||||
|
|
|
|||
22
test/test.ts
22
test/test.ts
|
|
@ -1317,7 +1317,6 @@ describe('基础测试', function () {
|
|||
}
|
||||
}, context, {});
|
||||
|
||||
|
||||
const row12 = store.select('oper', {
|
||||
data: {
|
||||
id: 1,
|
||||
|
|
@ -1335,6 +1334,26 @@ describe('基础测试', function () {
|
|||
}
|
||||
}
|
||||
}, context, {});
|
||||
|
||||
const row13 = store.select('oper', {
|
||||
data: {
|
||||
id: 1,
|
||||
data: {
|
||||
name: 1,
|
||||
price: 1,
|
||||
},
|
||||
},
|
||||
filter: {
|
||||
id,
|
||||
data: {
|
||||
price: {
|
||||
$length: {
|
||||
$gt: 3,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
}, context, {});
|
||||
context.commit();
|
||||
assert(row.length === 1);
|
||||
assert(row2.length === 0);
|
||||
|
|
@ -1348,6 +1367,7 @@ describe('基础测试', function () {
|
|||
assert(row10.length === 1);
|
||||
assert(row11.length === 0);
|
||||
assert(row12.length === 1);
|
||||
assert(row13.length === 0);
|
||||
// console.log(JSON.stringify(row7));
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue