Breeze.JS for SharePoint 2013错误保存更改

问题描述:

对象 extraMetadata 未定义,并在第247行 breeze.labs.dataservice.sharepoint.js 引发错误>

The object extraMetadata is undefined and throwing an error on line 247 of breeze.labs.dataservice.sharepoint.js

rawEntity.__metadata = { 'type': aspect.extraMetadata.type };

我怀疑是因为我没有定义 __ metadata 对象在我的微风的实体定义中。任何有关如何正确定义我的类型的建议都将受到欢迎!这是我对其中一个对象的类型定义。

I suspect it is because I have not defined the type found in __metadata object on my entity definitions for breeze. Any suggestions on how to define my type correctly would be very welcome! Here is my type definition for one of the objects.

   models.Project = {
        name: 'Project',
        defaultResourceName: 'getbytitle(\'Projects\')/items',
        dataProperties: {
            ID: {
                type: breeze.DataType.Int32
            },
            Title: {
                nullable: false
            },
            StatusId: {
                type: breeze.DataType.Int32,
                nullable: false
            },
            SelectedApproverId: {
                type: breeze.DataType.Int32,
                nullable: false
            },
            Created: {
                type: breeze.DataType.DateTime
            },
            Modified: {
                type: breeze.DataType.DateTime
            }
        },
        navigationProperties: {
            Status: {
                type: "Status",
                foreignKeyNames: ['StatusId'],
                hasMany: false
            },
            SelectedApprover: {
               type: "User",
               foreignKeyNames: ["SelectedApproverId"]
            }
        }
    };

更新时间:2013年11月11日

如果我运行以下查询:

    return breeze.EntityQuery
           .from(metadataStore.getEntityType('Project').defaultResourceName)
           .orderBy('Created desc')
           .using(manager)
           .execute()
           .then(function (data) {
                console.log(data.results);
                return data.results;
           });

结果是缺少 __ metadata 属性。我想弄清楚为什么会这样。

the results are an array of simple JavaScript objects, not Breeze Entities, that lack an __metadata properties. I'm trying to figure out why this is the case.

更新时间:2014年11月12日

我已经确认当我在 navigationProperties 下定义了多个实体时,会出现此问题。

I have confirmed that this issue presents itself when I have multiple entities defined under navigationProperties.

有一段时间没有帖子了,但我将分享我发现的问题以及如何为我解决该问题(因为我花了很长时间) 。

There hasn't been a post in a while but I am going to share what I found as the problem and how I resolved it for me (because it took me a long time).

基本上 breeze.labs.dataservice.sharepoint 适配器具有函数 serverTypeNameToClientDefault() 期望__metadata类型字段中的 REST / OData 返回的SharePoint自定义列表类型在精确

Basically the breeze.labs.dataservice.sharepoint adapter has a function serverTypeNameToClientDefault() that expects the SharePoint custom list type as returned by REST/OData in the __metadata "type" field to be in the exact format of:

SP.Data.**mylistname**sListItem**  (notice the "sListItem" suffix; ;  Ex. SP.Data.CustomersListItem)

此函数执行字符串正则表达式从中提取Breeze实体名称SharePoint类型,并使用该名称在元数据存储中查找实体(上例中为客户)。如果没有匹配项,Breeze将找不到您的实体,并将返回一个基本对象而不是Breeze实体。因此,从SharePoint返回的REST JSON结果,即使它确实具有__metadata属性,也不会转换为包含属性 entityAspect.extraMetadata 的Breeze实体。这就是导致错误 无法获取未定义或空引用的属性'类型'的原因。

This function does a string regex to extract the Breeze entity name from the SharePoint type and uses that name to look up the entity in the metadata store ("Customer" in the above example). If there is no match, Breeze will not find your entity and will return a basic object instead of a Breeze entity. Therefore your REST JSON result returned from SharePoint, even though it does have the __metadata property is not converted into a Breeze entity that contains the property entityAspect.extraMetadata, among other things. This is what leads to the error "Unable to get property 'type' of undefined or null reference"

如果我不在乎自定义列表的URL是什么,我只是确保在SharePoint设置我的自定义列表时,它会根据Breeze的期望生成一个名称。您可以通过设置 ListInstance 元素的 Url 属性来完成此操作,例如:

For my solution, since in my case I don't care as much what the URL of my custom lists are, I just made sure that when my custom list was provisioned by SharePoint that it resulted in a name according to what Breeze expects. You accomplish this by setting the Url attribute of the ListInstance element like this:

<ListInstance 
      Title="My Customers" 
      OnQuickLaunch="TRUE" 
      TemplateType="10000" 
      Url="Lists/Customers"    <!-- List/Customer will not work -->
      Description="My List Instance">
      ...

更好的解决方案是使 serverTypeNameToClientDefault()功能更强大或可以在本地解决它,但希望可以在以后的适配器版本中解决。

The better solution would be to make the serverTypeNameToClientDefault() function more robust or fix it to my needs locally but hopefully this can be addressed in a future version of the adapter.

注意我已经使用以下配置(未列出所有依赖项)测试了该解决方案:
Breeze.Client 1.4.9与Breeze.DataService.SharePoint 0.2.3

Breeze.Client 1.5.0使用Breeze.DataService.SharePoint 0.3.2

Note that I have tested this solution with the following configurations (not all dependencies listed): Breeze.Client 1.4.9 with Breeze.DataService.SharePoint 0.2.3
Breeze.Client 1.5.0 with Breeze.DataService.SharePoint 0.3.2

还请注意,如上所述,当发生这种情况时,适配器的0.3.2版本现在会显示更好的错误消息- 缺少更新/删除实体的多余元数据

Also note that the 0.3.2 version of the adapter now displays a better error message when this happens as mentioned above -- "Missing the extra metadata for an update/delete entity"; but it doesn't fix the problem.

希望这对某人有帮助。