diff --git a/es/store.js b/es/store.js index 2388a2d..05009bb 100644 --- a/es/store.js +++ b/es/store.js @@ -566,6 +566,16 @@ export default class TreeStore extends CascadeStore { }).length > 0; }; } + 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; + }; + } default: { throw new Error(`predicate ${predicate} is not recoganized`); } diff --git a/lib/store.js b/lib/store.js index 06b5a9c..7addd51 100644 --- a/lib/store.js +++ b/lib/store.js @@ -568,6 +568,16 @@ class TreeStore extends CascadeStore_1.CascadeStore { }).length > 0; }; } + 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; + }; + } default: { throw new Error(`predicate ${predicate} is not recoganized`); } diff --git a/src/store.ts b/src/store.ts index c1f95fa..62dfdab 100644 --- a/src/store.ts +++ b/src/store.ts @@ -707,6 +707,16 @@ export default class TreeStore extends C }).length > 0; }; } + 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; + } + } default: { throw new Error(`predicate ${predicate} is not recoganized`); } @@ -2281,7 +2291,7 @@ export default class TreeStore extends C } else if (this.store[entity]?.[id]) { const row = this.constructRow(this.store[entity]![id]!, context); - if ((row[UpdateAtAttribute] as number) <= (d[entity]![id]![UpdateAtAttribute] as number)) { + if ((row![UpdateAtAttribute] as number) <= (d[entity]![id]![UpdateAtAttribute] as number)) { this.updateAbjointRow(entity, { id: 'dummy', action: 'update', diff --git a/test/test.ts b/test/test.ts index 78422c4..f1f7eb2 100644 --- a/test/test.ts +++ b/test/test.ts @@ -1317,6 +1317,24 @@ describe('基础测试', function () { } }, context, {}); + + const row12 = store.select('oper', { + data: { + id: 1, + data: { + name: 1, + price: 1, + }, + }, + filter: { + id, + data: { + price: { + $length: 3, + }, + } + } + }, context, {}); context.commit(); assert(row.length === 1); assert(row2.length === 0); @@ -1329,6 +1347,7 @@ describe('基础测试', function () { assert(row9.length === 1); assert(row10.length === 1); assert(row11.length === 0); + assert(row12.length === 1); // console.log(JSON.stringify(row7)); });