首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用jQuery检查SharePoint字段是否存在

使用jQuery检查SharePoint字段是否存在
EN

Stack Overflow用户
提问于 2014-07-31 16:08:35
回答 2查看 883关注 0票数 0

我想使用一个脚本来检查表单中是否存在一个名为Delivery Terms的字段,如果存在,则应该执行一个函数。

为什么以下选项不起作用?

代码语言:javascript
复制
if ($('nobr:contains("Delivery Terms")').length > 0) {
    $jq(document).ready(function () {
        {
            $jq().SPServices.SPCascadeDropdowns({
                relationshipList: "Machine",
                relationshipListParentColumn: "Costing_x0020_Group_x003a__x0020",
                relationshipListChildColumn: "Title",
                parentColumn: "Manufacturing Unit",
                childColumn: "Machine",
                debug: true
            });
        }
    }
});

下面是我使用的完整代码:

代码语言:javascript
复制
<script type="text/javascript">

//Fixes the design for dropdowns with more than 20 items 
$jq().SPServices.SPComplexToSimpleDropdown({
 columnName: "Responsible Designer/Quoter"
});
$jq().SPServices.SPComplexToSimpleDropdown({
 columnName: "Material No. 1"
});
$jq().SPServices.SPComplexToSimpleDropdown({
 columnName: "Material No. 2"
});

if ($('nobr:contains("Delivery Terms")').length > 0) {
    $jq(document).ready(function () {
        {
        $jq().SPServices.SPCascadeDropdowns({
            relationshipList:"Machine",
            relationshipListParentColumn:"Costing_x0020_Group_x003a__x0020",
            relationshipListChildColumn:"Title",
            parentColumn:"Manufacturing Unit",
            childColumn:"Machine",
            debug:true
        });
        $jq().SPServices.SPCascadeDropdowns({
            relationshipList:"Art no",
            relationshipListParentColumn:"Costing_x0020_Group_x003a__x0020",
            relationshipListChildColumn:"Title",
            parentColumn:"Manufacturing Unit",
            childColumn:"Material No. 1",
            debug:true
        }); 
        $jq().SPServices.SPCascadeDropdowns({
            relationshipList:"Art no",
            relationshipListParentColumn:"Costing_x0020_Group_x003a__x0020",
            relationshipListChildColumn:"Title",
            parentColumn:"Manufacturing Unit",
            childColumn:"Material No. 2",
            debug:true
        });
        $jq().SPServices.SPCascadeDropdowns({
            relationshipList:"Approval",
            relationshipListParentColumn:"Title",
            relationshipListChildColumn:"Reason",
            parentColumn:"Issue Status",
            childColumn:"Reason to decline",
            debug:true
        });
        $jq().SPServices.SPCascadeDropdowns({
            relationshipList:"Responsible Designer",
            relationshipListParentColumn:"Costing_x0020_Group_x003a__x0020",
            relationshipListChildColumn:"Title",
            parentColumn:"Manufacturing Unit",
            childColumn:"Responsible Designer/Quoter",
            debug:true
        });

        $jq().SPServices.SPCascadeDropdowns({
            relationshipList:"Delivery Terms",
            relationshipListParentColumn:"Manufacturing_x0020_Place",
            relationshipListChildColumn:"Title",
            parentColumn:"Manufacturing Unit",
            childColumn:"Delivery Terms",
            debug:true
        });

        $jq().SPServices.SPCascadeDropdowns({
            relationshipList:"Payment Terms",
            relationshipListParentColumn:"Manufacturing_x0020_Place",
            relationshipListChildColumn:"Title",
            parentColumn:"Manufacturing Unit",
            childColumn:"Payment Terms",
            debug:true
         });
        }
    }
});

</script>
EN

回答 2

Stack Overflow用户

发布于 2014-07-31 16:36:00

看起来"$('nobr:contains("Delivery Terms")').length“不是你需要的。试试下面的其中一种:

代码语言:javascript
复制
$('nobr:contains("Delivery Terms")').val().length
$('nobr:contains("Delivery Terms")').text().length

另外,检查选择器"nobr:contains("Delivery Terms")“是否找到所需的元素,它可能是空的,并且代码不会调用。

票数 0
EN

Stack Overflow用户

发布于 2014-08-01 16:54:48

只需将if语句放入document.ready中即可

代码语言:javascript
复制
//Fixes the design for dropdowns with more than 20 items 
$().SPServices.SPComplexToSimpleDropdown({
    columnName: "Responsible Designer/Quoter"
});
$().SPServices.SPComplexToSimpleDropdown({
    columnName: "Material No. 1"
});
$().SPServices.SPComplexToSimpleDropdown({
    columnName: "Material No. 2"
});
$(document).ready(function () {
    if ($('nobr:contains("Delivery Terms")').length > 0) {
        $().SPServices.SPCascadeDropdowns({
            relationshipList: "Machine",
            relationshipListParentColumn: "Costing_x0020_Group_x003a__x0020",
            relationshipListChildColumn: "Title",
            parentColumn: "Manufacturing Unit",
            childColumn: "Machine",
            debug: true
        });
        $().SPServices.SPCascadeDropdowns({
            relationshipList: "Art no",
            relationshipListParentColumn: "Costing_x0020_Group_x003a__x0020",
            relationshipListChildColumn: "Title",
            parentColumn: "Manufacturing Unit",
            childColumn: "Material No. 1",
            debug: true
        });
        $().SPServices.SPCascadeDropdowns({
            relationshipList: "Art no",
            relationshipListParentColumn: "Costing_x0020_Group_x003a__x0020",
            relationshipListChildColumn: "Title",
            parentColumn: "Manufacturing Unit",
            childColumn: "Material No. 2",
            debug: true
        });
        $().SPServices.SPCascadeDropdowns({
            relationshipList: "Approval",
            relationshipListParentColumn: "Title",
            relationshipListChildColumn: "Reason",
            parentColumn: "Issue Status",
            childColumn: "Reason to decline",
            debug: true
        });
        $().SPServices.SPCascadeDropdowns({
            relationshipList: "Responsible Designer",
            relationshipListParentColumn: "Costing_x0020_Group_x003a__x0020",
            relationshipListChildColumn: "Title",
            parentColumn: "Manufacturing Unit",
            childColumn: "Responsible Designer/Quoter",
            debug: true
        });

        $().SPServices.SPCascadeDropdowns({
            relationshipList: "Delivery Terms",
            relationshipListParentColumn: "Manufacturing_x0020_Place",
            relationshipListChildColumn: "Title",
            parentColumn: "Manufacturing Unit",
            childColumn: "Delivery Terms",
            debug: true
        });

        $().SPServices.SPCascadeDropdowns({
            relationshipList: "Payment Terms",
            relationshipListParentColumn: "Manufacturing_x0020_Place",
            relationshipListChildColumn: "Title",
            parentColumn: "Manufacturing Unit",
            childColumn: "Payment Terms",
            debug: true
        });
    }
});

</script>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25053811

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档