打开vs2012新建项目。

SharePoint2013 App 开发中 自定义网站栏,内容类型,列表。

选择Sharepoint hosted模式。

SharePoint2013 App 开发中 自定义网站栏,内容类型,列表。

一个app开发的项目就创建好了。

创建网站栏

1.右键项目》添加》新建项》Site column 创建一个网站栏

2.在element.xml中添加以下字段。

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Field
       ID="{0e87dcf9-cdee-4842-956c-83769804bcae}"
       Name="DemoNumber"
       DisplayName="编号"
       Type="Text"
       Required="True"
       Group="Demo"
       >
  </Field>
  <Field
      ID="{076B7907-8A20-4EE9-9004-0C0DED00C628}"
      Name="DemoName"
      DisplayName="名称"
      Type="Text"
      Required="True"
      Group="Demo"
      >
  </Field>
  <Field
    ID="{C808C172-03C3-413C-AF10-4855B555ED25}"
    Name="DemoType"
    DisplayName="类型"
    Type="Lookup"
    Required="True"
    List="Lists/DemoType"
    ShowField="Title"
    Group="Demo"
    >
  </Field>
  <Field
    ID="{E4CD63A6-C6CB-46D0-93D6-A4AD93497D92}"
    Name="DemoOperator"
    DisplayName="经办人"
    Type="User"
    List="UserInfo"
    Required="True"
    ShowField="ImnName"
    UserSelectionMode="PeopleOnly"
    UserSelectionScope="0"
    Group="Demo"
  >
  </Field>
  <Field
    ID="{CECCCC3E-1D00-4442-8018-52FC260C5ADF}"
    Name="DemoOperationTime"
    DisplayName="操作时间"
    Type="DateTime"
    Required="True"
    Group="Demo"
    >
  </Field>
</Elements>

 

这个网站栏包含了几个基本的字段。

创建内容类型

1.右键项目》添加》新建项》ContentType

SharePoint2013 App 开发中 自定义网站栏,内容类型,列表。

2.选择项目

SharePoint2013 App 开发中 自定义网站栏,内容类型,列表。

 3.双击打开内容类型,如下图所示

SharePoint2013 App 开发中 自定义网站栏,内容类型,列表。

箭头所指的地方是选择你内容类型的分组,这里也可以直接输入你的组名。如果组名不存在,会自动创建。我们还是写demo组

4.点击columns标签。

在里面输入网站栏中定义的字段,就可以搜索到。

SharePoint2013 App 开发中 自定义网站栏,内容类型,列表。

现在我们把字段都添加进来了。

创建自定义列表

1.右键项目》添加》新建项

SharePoint2013 App 开发中 自定义网站栏,内容类型,列表。

2.创建一个名字为TestList的自定义列表

SharePoint2013 App 开发中 自定义网站栏,内容类型,列表。

3.打开list,选择list标签查看list属性

SharePoint2013 App 开发中 自定义网站栏,内容类型,列表。

4.添加内容类型

SharePoint2013 App 开发中 自定义网站栏,内容类型,列表。

点击Content Types 会弹出一个对话框,自定义列表默认会带项目内容类型。

输入我们刚创建的TestContentType 点击OK 会有惊喜哦!!!

SharePoint2013 App 开发中 自定义网站栏,内容类型,列表。

TestContentType内容类型中的字段都会添加到列表中来。

到这一步,大家看一下,上面我们创建网站栏的代码

  <Field
    ID="{C808C172-03C3-413C-AF10-4855B555ED25}"
    Name="DemoType"
    DisplayName="类型"
    Type="Lookup"
    Required="True"
    List="Lists/DemoType"
    ShowField="Title"
    Group="Demo"
    >
  </Field>

有这样一个字段,这个字段有一个属性 List  其实这个字段是查阅项,list指向的是另一个列表的URL

ShowField属性是要显示DemoType这个列表中的哪个字段。

按照同样的办法,我们创建一个名字为DemoType的自定义列表。

OK  右键项目 部署。然后我们去看看这个app

用工具打开这个站点。

SharePoint2013 App 开发中 自定义网站栏,内容类型,列表。

我们先在DemoType中添加3条数据

然后在去TestList添加新项目就可以看到了

SharePoint2013 App 开发中 自定义网站栏,内容类型,列表。

OK 相信大家很容易就能掌握了。如果觉得写的好,多多支持哈。

Sharepoint-hosted开发模式,都依赖Javascript Object Model 来交互数据

回头我会把JavaScript Object Model的一些疑难问题解决方案给大家奉上。

 

相关文章: