问题描述
我有三个SharePoint 2016列表:
I have three SharePoint 2016 lists:
- 组织
- 部门
- 群组
群组按部门排序,部门按组织排序。
Groups are sorted by Department and Departments are sorted by Organization.
每个列表中的标题字段用于组,org或dept的名称,每个列表中都有一个下拉列表,用于选择相应项目的父项。
The title field in each list is used for the name of the group, org or dept and there is a dropdown in each list to select the parent of that respective item.
在我的一个表单中,用户应该选择拥有特定软件标题的组织,部门和组。我正在尝试使用SPServices.SPCascadeDropdowns来仅显示所选组织的部门,但它根本没有做任何事情。
In one of my forms, the user is supposed to select the org, dept and group who owns a specific software title. I am attempting to use SPServices.SPCascadeDropdowns to show only the departments for the selected org, but it isn't doing anything at all.
表单中的相关字段是:
<td valign="top" class="ms-formlabel">
<H3 class="ms-standardheader">
<nobr>Organization<span class="ms-formvalidation"> *</span></nobr>
</H3>
</td>
<td valign="top" class="ms-formbody">
<SharePoint:FormField runat="server" id="ff9{$Pos}" ControlMode="New"
FieldName="Organization"
__designer:bind="{ddwrt:DataBind('i',concat('ff9',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Organization')}"/>
<SharePoint:FieldDescription runat="server" id="ff9description{$Pos}" FieldName="Organization" ControlMode="New"/>
</td>
<td valign="top" class="ms-formlabel">
<H3 class="ms-standardheader">
<nobr>Department<span class="ms-formvalidation"> *</span></nobr>
</H3>
</td>
<td valign="top" class="ms-formbody">
<SharePoint:FormField runat="server" id="ff10{$Pos}" ControlMode="New"
FieldName="Department"
__designer:bind="{ddwrt:DataBind('i',concat('ff10',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Department')}"/>
<SharePoint:FieldDescription runat="server" id="ff10description{$Pos}" FieldName="Department" ControlMode="New"/>
</td>
我使用的Javascript是:
The Javascript I'm using is:
$(document).ready(function(){
$().SPServices.SPCascadeDropdowns({
relationshipList: "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}",
relationshipListParentColumn: "Organization",
relationshipListChildColumn: "Title",
parentColumn: "Organization",
childColumn: "Department",
debug: true
});
});
我已经加载了jQuery 3.2.1和jQuery.SPServices-2014.02.min.js。我在Chrome控制台中没有出现任何错误,它根本就没有做任何事情。如果我在$()。SPServices上休息一下,它确实打了,所以我知道它被调用了。知道我做错了吗?
I've loaded jQuery 3.2.1 and jQuery.SPServices-2014.02.min.js. I'm getting no errors in Chrome console, it just isn't doing anything at all. If I put a break at $().SPServices, it does hit so I know it's being called. Any idea what I'm doing wrong?
推荐答案
考虑到你没有提供你的数据结构,我已经带来我的;)
Taking into consideration that you didn't provided your data structure, i've brought mine ;)
使用此PowerShell脚本在特定网站集中创建结构:
Use this PowerShell script to create structure in a specific site collection:
$web = get-spweb <YOUR URL>
$template = $web.ListTemplates | where name -eq 'Custom List'
$organizationsListId = $web.Lists.Add("Organizations", "", $template)
$departmentsListId = $web.Lists.Add("Departments", "", $template)
$groupsListId = $web.Lists.Add("Groups", "", $template)
$organizationsLookup = $web.Fields.AddLookup("OrganizationsLookup", $organizationsListId, $false)
$departmentsLookup = $web.Fields.AddLookup("DepartmentsLookup", $departmentsListId, $false)
$organizations = $web.Lists[$organizationsListId]
$departments = $web.Lists[$departmentsListId]
$groups = $web.Lists[$groupsListId]
$departments.Fields.Add($web.Fields.GetFieldByInternalName("OrganizationsLookup"))
$groups.Fields.Add($web.Fields.GetFieldByInternalName("DepartmentsLookup"))
$groups.Fields.Add($web.Fields.GetFieldByInternalName("OrganizationsLookup"))
$organizationsLookupInList = $departments.Fields.GetFieldByInternalName("OrganizationsLookup");
$organizationsLookupInList.LookupField = "Title"
$organizationsLookupInList.Update()
$departmentsLookupInList = $groups.Fields.GetFieldByInternalName("DepartmentsLookup");
$departmentsLookupInList.LookupField = "Title"
$departmentsLookupInList.Update()
$organizationsLookupInList1 = $groups.Fields.GetFieldByInternalName("OrganizationsLookup");
$organizationsLookupInList1.LookupField = "Title"
$organizationsLookupInList1.Update()
function AddListItem($list, $title)
{
$itm = $list.AddItem()
$itm["Title"] = $title
$itm.Update()
return $itm
}
function AddListItemDepartments($list, $title, $lookupIdOrg)
{
$itm = AddListItem $list $title
$itm["OrganizationsLookup"] = $lookupIdOrg
$itm.Update();
return $itm
}
function AddListItemGroups($list, $title, $lookupIdOrg, $lookupIdDep)
{
$itm = AddListItemDepartments $list $title $lookupIdOrg
$itm["DepartmentsLookup"] = $lookupIdDep
$itm.Update();
return $itm
}
$org1Id = (AddListItem $organizations "AAA NET").ID
$org2Id = (AddListItem $organizations "BBB NET").ID
$org3Id = (AddListItem $organizations "CCC NET").ID
$org4Id = (AddListItem $organizations "DDD NET").ID
$dep1Id = (AddListItemDepartments $departments "Finance" $org1Id).ID
$dep2Id = (AddListItemDepartments $departments "IT" $org1Id).ID
$dep3Id = (AddListItemDepartments $departments "Finance" $org2Id).ID
$dep4Id = (AddListItemDepartments $departments "Social" $org2Id).ID
$dep5Id = (AddListItemDepartments $departments "Fun" $org2Id).ID
$dep6Id = (AddListItemDepartments $departments "Sport" $org2Id).ID
$dep7Id = (AddListItemDepartments $departments "Knowledge" $org3Id).ID
$dep8Id = (AddListItemDepartments $departments "Sport" $org3Id).ID
下一步:
- 打开群组列表新形式页面。
- 从右上角点击编辑页面ttings。
-
编辑xsltlistviewformwebpart,将jquery和spservices附加到
JSLink
property
ie:
- Open groups list newform page.
- Hit edit page from top-right settings.
Edit xsltlistviewformwebpart, attach jquery and spservices to
JSLink
propertyie:
~site / siteassets / jquery-3.2.1.min.js | ~site / siteassets / jquery.SPServices-2014.02.min.js
将CEWP添加到页面,将其移到webpart下面,插入你的js级联下拉代码:
Add CEWP to page, move it below form webpart and insert your js cascading dropdowns code:
代码(见评论)
$(document).ready(function(){
$().SPServices.SPCascadeDropdowns({
relationshipList: "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}", // Your departments list id
relationshipListParentColumn: "OrganizationsLookup",
relationshipListChildColumn: "Title",
parentColumn: "OrganizationsLookup",
childColumn: "DepartmentsLookup",
debug: true
});
});
这应该有效(同时使用jquery 3.2.1)
And this should work (also with jquery 3.2.1)
这篇关于SPServices.SPCascadeDropdowns没有正确级联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!