Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/431.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript SPServices.spcascade下拉列表未正确层叠_Javascript_Jquery_Sharepoint - Fatal编程技术网

Javascript SPServices.spcascade下拉列表未正确层叠

Javascript SPServices.spcascade下拉列表未正确层叠,javascript,jquery,sharepoint,Javascript,Jquery,Sharepoint,我有三个SharePoint 2016列表: 组织机构 部门 团体 组按部门排序,部门按组织排序 每个列表中的标题字段用于组、组织或部门的名称,每个列表中都有一个下拉列表,用于选择相应项目的父项 在我的一个表单中,用户应该选择拥有特定软件标题的组织、部门和组。我试图使用SPServices.spcascade下拉列表仅显示所选组织的部门,但它根本不做任何事情 表单中的相关字段为: <td valign="top" class="ms-formlabel"> <H3 cl

我有三个SharePoint 2016列表:

  • 组织机构
  • 部门
  • 团体
组按部门排序,部门按组织排序

每个列表中的标题字段用于组、组织或部门的名称,每个列表中都有一个下拉列表,用于选择相应项目的父项

在我的一个表单中,用户应该选择拥有特定软件标题的组织、部门和组。我试图使用SPServices.spcascade下拉列表仅显示所选组织的部门,但它根本不做任何事情

表单中的相关字段为:

<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>

我已经加载了jQuery 3.2.1和jQuery.SPServices-2014.02.min.js。我在Chrome控制台中没有发现任何错误,只是它什么也没做。如果我在$().SPServices上放一个断点,它确实会命中,所以我知道它正在被调用。知道我做错了什么吗?

看起来问题是因为您使用的是
jQuery 3.2.1

根据文档,建议您使用
jquery1.10或更高版本

建议您删除
3.2.1
版本,改为使用
1.12
版本,然后进行检查

参考文献-


jQuery的下载链接-

考虑到您没有提供数据结构,我带来了我的;)

使用此PowerShell脚本在特定网站集中创建结构:

$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

这应该可以(同样适用于jquery 3.2.1)

您的列表关系模型是什么?部门有对组织的查找,组有对组织和部门的查找?如果其中一个字段是必需的,建议您检查此线程。请记住,这个库是为2007/2010年构建的,您的回答让我找到了正确的代码。结果表明,spcascadeddropdowns函数中的parentColumn字段将尝试使用jQuery查找具有parentColumn中指定标题的select元素。我原以为标题是“组织”,但SharePoint正在将标题设置为“组织必填字段”。很高兴您找到了它!我验证了SPServices是否可以与最新的jQuery一起使用。
$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
$(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
    });
});