自定义列表定义 + 自定义内容类型 = 只显示一个表单字段? [英] Custom list definition + custom content type = showing only one form field?

查看:37
本文介绍了自定义列表定义 + 自定义内容类型 = 只显示一个表单字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用功能部署自定义字段、内容类型和列表.到目前为止,我有一个引用自定义和内置字段的内容类型.内容类型继承 Item (0x01).

Trying to use features to deploy custom fields, content type and list. So far I have a content type referencing custom and builtin fields. Content type inherits Item (0x01).

现在,我创建引用内容类型和字段(内置和自定义的)的自定义列表定义.我明确地将 ShowInDisplayForm、ShowInEditForm、ShowInNewForm 值设置为 true,但是当我部署功能并根据定义创建列表时,我得到的只是所有表单中的一个 Title 字段!

Now, I create custom list definition that references content type and fields (builtin and custom ones). I explicitly set ShowInDisplayForm, ShowInEditForm, ShowInNewForm values to true, however when I deploy feature and create list based on definition, all I get is only a single Title field in all forms!

但是,如果我将 UI 中的字段添加到列表中,它会显示在表单中!此外,如果我从 UI 创建自定义列表并添加内容类型,这些字段将显示在表单中!

However if I add field from UI to the list, it shows up in the form! Furthermore, if I create custom list from UI and add the content type, those fields are showing up in forms!

这是怎么回事?

顺便说一下,我在 Visual Studio 中使用了 VSeWSS 工具,所以它已经正确地生成了很多东西.

By the way, I use VSeWSS tool for Visual Studio so it already genrates alot of stuff correctly.

一些代码:

<ContentTypes>
  <ContentTypeRef ID="0x01003420C661289843dbAB9E41F43C23BFD0" />
</ContentTypes>
<Fields>
  <Field ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" Group="$Resources:core,Extended_Columns" Required="TRUE" ShowInDisplayForm="TRUE" ShowInEditForm="TRUE" ShowInNewForm="TRUE" Type="Text" Sortable="TRUE" Filterable="TRUE" SourceID="http://schemas.microsoft.com/sharepoint/v3" />
  <Field ID="{B4629012-C672-4911-B0D0-B9CB2DA44ED2}" DisplayName="Jautājumu pacēla" Group="$Resources:core,Extended_Columns" Name="QuestionRisedBy" Required="TRUE" ShowInDisplayForm="TRUE" ShowInEditForm="TRUE" ShowInNewForm="TRUE" Type="User" Sortable="TRUE" Filterable="TRUE" SourceID="http://schemas.microsoft.com/sharepoint/v3" />
  <Field ID="{6DF9BD52-550E-4a30-BC31-A4366832A87F}" DisplayName="Komentārs" Group="$Resources:core,Extended_Columns" Name="Comment" AppendOnly="TRUE" Required="FALSE" NumLines="12" Type="Note" ShowInDisplayForm="TRUE" ShowInEditForm="TRUE" ShowInNewForm="TRUE" Sortable="FALSE" Filterable="FALSE" SourceID="http://schemas.microsoft.com/sharepoint/v3" />
  <Field ID="{FC072586-E8BB-444f-AAA4-8D5745FBC096}" DisplayName="ParentItemId" Group="$Resources:core,Extended_Columns" Name="AgendaParentItemId" Required="TRUE" Type="Integer" Sortable="FALSE" Filterable="FALSE" SourceID="http://schemas.microsoft.com/sharepoint/v3" />
  <Field ID="{29207E42-E107-4379-B620-BAAFC461276B}" DisplayName="AgendaRootItemId" Group="$Resources:core,Extended_Columns" Name="AgendaRootItemId" Required="TRUE" Type="Integer" Sortable="FALSE" Filterable="FALSE" SourceID="http://schemas.microsoft.com/sharepoint/v3" />
  <Field ID="{06063FDB-3C2A-4141-91F7-28C2739CE6B5}" DisplayName="AgendaItemClosed" Group="$Resources:core,Extended_Columns" Name="AgendaItemClosed" Required="FALSE" Type="Boolean" Sortable="TRUE" Filterable="TRUE" SourceID="http://schemas.microsoft.com/sharepoint/v3" />
</Fields>

推荐答案

是的,ContentType 具有所有字段的 FieldRefs(嗯,不是继承的).但是,在 schema.xml 中定义内容类型时,我读到了 您还必须显式定义字段(这很奇怪),但是如果您以编程方式添加 ContentType,那么它会正确地将 CType 字段添加到定义中.

Yes, ContentType has FieldRefs for all the fields (Well, not inherited ones). However I read that when defining contet types in schema.xml, you must explicitly define Field`s also (that's weird), however if you add ContentType programmatically, then it correctly adds CType fields to definition.

顺便说一下,你看到的是VSeWSS(微软VS扩展)工具生成的(所有参考).

By the way, what you see is what VSeWSS (microsoft extension for VS) tool generated (all the references).

相当来自 SharePoint 博客:

您需要做的是添加完全相同的元素内容中的元素类型,包括相同的 ID.这是一个有点奇怪,但实际上你需要两次定义字段,都在内容类型和 schema.xml使这项工作.你可以跳过组和其他一些属性.

What you need to do is to add the exact same elements to the element as in the content type, including the same ID. This is a little strange, but in fact you need to define the fields twice, both in the content type and in the schema.xml to make this work. You can skip the Group and a few other properties.

然而,如果我不使用 Fields,我会得到一个例外:

However if I won't use Fields, I`ll get an exception:

[COMException (0x80004005): Nevar pabeigt šo darbību.

Lūdzu, mēģiniet vēlreiz.]
   Microsoft.SharePoint.Library.SPRequestInternalClass.GetViewsSchemaXml(String bstrUrl, String bstrListName, Boolean bFullBlown, ISP2DSafeArrayWriter p2DWriter, Int32& plDefaultViewIndex) +0
   Microsoft.SharePoint.Library.SPRequest.GetViewsSchemaXml(String bstrUrl, String bstrListName, Boolean bFullBlown, ISP2DSafeArrayWriter p2DWriter, Int32& plDefaultViewIndex) +122

哦,好吧,无论如何,我在某处读到一篇文章(再也找不到那篇文章了),建议使用功能接收器添加内容类型,然后它会正确显示表单中的字段.

Oh, well, anyway, I read somwhere an article (can't find that article no more)that suggest adding content type with feature receivers, then it properly shows up fields in forms.

这篇关于自定义列表定义 + 自定义内容类型 = 只显示一个表单字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆