gpt4 book ai didi

javascript - 类型错误 : Object [object Array] has no method 'getProperty'

转载 作者:行者123 更新时间:2023-11-30 06:27:34 25 4
gpt4 key购买 nike

我对发布问题这件事有点陌生,所以请保持温和!

我将 Breeze 用作“Hot Towel”SPA 堆栈的一部分,并从用 PHP 编写的自定义 WebApi 端点检索数据。这不是一个完整的实现,我只是写了足够的东西来满足我的需要。

我的端点生成的元数据如下:

 {
"shortName": "Project",
"namespace": "WebApi.ORM.Cartesius",
"autoGeneratedKeyType": "Identity",
"defaultResourceName": "Project",
"dataProperties": [
{
"name": "id",
"isPartOfKey": true,
"isNullable": false,
"dataType": "Int32"
},
{
"name": "title",
"isNullable": false,
"maxLength": 256,
"dataType": "String"
},
{
"name": "date",
"isNullable": false,
"dataType": "DateTime"
},
{
"name": "review_date",
"isNullable": true,
"dataType": "DateTime"
},
{
"name": "summary",
"isNullable": true,
"dataType": "String"
}
],
"navigationProperties": [
{
"name": "Team",
"entityTypeName": "Team:#WebApi.ORM.Cartesius",
"isScalar": true,
"associationName": "team_project_id_fkey",
"invForeignKeyNames": [
"project_id"
]
},
{
"name": "ProjectAuthor",
"entityTypeName": "ProjectAuthor:#WebApi.ORM.Cartesius",
"isScalar": true,
"associationName": "project_author_project_id_fkey",
"invForeignKeyNames": [
"project_id"
]
},
{
"name": "Itinerary",
"entityTypeName": "Itinerary:#WebApi.ORM.Cartesius",
"isScalar": true,
"associationName": "itinerary_project_id_fkey",
"invForeignKeyNames": [
"project_id"
]
},

一切正常,直到我尝试扩展我的查询:

var query = new breeze.EntityQuery()
.from("Project")
.where("id","eq",project.id)
.expand("ProjectAuthor");

此查询从我的端点返回以下内容:

[
{
"$id": 1,
"$type": "WebApi.ORM.Cartesius.Project",
"id": 2,
"title": "teat",
"date": "2013-11-04 14:00:00+07",
"review_date": null,
"summary": null,
"ProjectAuthor": [
{
"$id": 2,
"$type": "WebApi.ORM.Cartesius.ProjectAuthor",
"id": 1,
"account_id": 1,
"project_id": 2,
"Project": [
{
"$ref": 1
}
]
},
{
"$id": 3,
"$type": "WebApi.ORM.Cartesius.ProjectAuthor",
"id": 3,
"account_id": 2,
"project_id": 2,
"Project": [
{
"$ref": 1
}
]
}
]
}

]

然后 Breeze 被它扔出窒息了:

TypeError: Object [object Array] has no method 'getProperty'

调试指向 Breeze 中的第 5059 行,它尝试在实体数组而不是单个实体上获取属性我认为这与导航属性是否设置为标量有关但切换它们没有区别.

我确定我做错了很多事,但我无法弄清楚它是什么,而且我有点碰壁了。我已经从头到尾阅读了文档,并尽我所能地实现了这一点,但我可能有点困惑。

如果我没有说清楚或提供足够的信息,请提前感谢您的帮助和道歉

最佳答案

我认为你的问题出在元数据上

     "name": "ProjectAuthor",
"entityTypeName": "ProjectAuthor:#WebApi.ORM.Cartesius",
"isScalar": true,
"associationName": "project_author_project_id_fkey",
"invForeignKeyNames": [
"project_id"
]
},

在那个导航属性 Project->ProjectAuthor 上,你告诉它它是一个标量,但它不在数据集中.. “项目作者”:[ { …………

我也遇到过这个问题.. 99% 的时间是元数据问题,如果不存在则开始将元数据分开,直到您隔离错误.. 虽然我确定这就是问题所在.. 您需要 hasMany 那里和反向导航上的 isScalar

关于javascript - 类型错误 : Object [object Array] has no method 'getProperty' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20184340/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com