TypeError:Object [object Array]没有方法'getProperty'

时间:2013-11-25 03:38:10

标签: javascript php breeze

我对整个发布一个问题的事情有点新意,所以请温柔一点!

我使用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
                }
            ]
        }
    ]
}

然后微风呛到了它:

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

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

我确定我正在做一些大错的事情,但我无法弄清楚它是什么,我有点像砖墙。我已经从上到下阅读了这些文档,我正在尽可能地理解这一点,但我可能会有点困惑。

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

1 个答案:

答案 0 :(得分:0)

我认为你的问题在于元数据

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

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

我有这个问题以及.. 99%的时间它的元数据问题,如果没有那么开始切割元数据,直到你隔离错误..虽然我确定这是问题..你需要一个hasMany那里反向导航上的isScalar