简体   繁体   中英

query against returned results in breeze

I would like to query against returned result, but when I use the following code, it throws an error:

 let em = new breeze.EntityManager('api/customer'); let serverQuery = breeze.EntityQuery.from('Customer'); let localQuery = breeze.EntityQuery.from('Customer').where('Id', '==', '1'); em.executeQuery(serverQuery) .then(data => { let localData = data.entityManager.executeQueryLocally(localQuery); //error }) .catch(error => { console.log(error); }); 

Error I get is:

Uncaught Error: Cannot find an entityType for resourceName: 'Customer'. Consider adding an 'EntityQuery.toType' call to your query or calling the MetadataStore.setEntityTypeForResourceName method to register an entityType for this resourceName.

I can see results are coming back when serverQuery is executed, but it doesn't like how I try to query against the returned results. I know I can get results by running localQuery through api call first time, but I want to get all customers (probably need to filter in some degree) first from the server then filter those customers when user enter, for example, customer's name, in an input field so that it won't try to fetch data from the server every time user changes customer name in that field. Most likely I am doing something wrong in the code above, but is it possible to do it with breeze?

Ok, I don't know if this is the best way to do it but this code seems to work:

 let em = new breeze.EntityManager('api/customer'); let serverQuery = breeze.EntityQuery.from('Customer').toType('Customer'); em.executeQuery(serverQuery) .then(data => { let localData = data.query.where('id', '==', '1').using(em).executeLocally(); //works! }) .catch(error => { console.log(error); }); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM