问题原因可能是由于在创建模型时未正确定义过滤器或过滤器语法不正确。以下是一些
type Person @model
@key(fields: ["id"])
@index(name: "nameIndex", fields: ["name"], queryField: "peopleByName")
{
id: ID!
name: String!
age: Int
}
import { DataStore } from 'aws-amplify';
DataStore.query(Person, c => c.name("contains", "John")).then(people => {
console.log(people);
});
import { DataStore } from 'aws-amplify';
DataStore.query(Person, c => c.name("startsWith", "John")).then(people => {
console.log(people);
});
import { DataStore } from 'aws-amplify';
DataStore.query(Person, c => c.name("beginsWith", "J").sort(SortOrder.ASCENDING)).then(people => {
console.log(people);
});