SharePoint的客户端分类选择器

时间:2018-08-28 12:07:21

标签: javascript sharepoint-2013 taxonomy

在内部部署SharePoint 2013上,使用以下博客为SharePoint实施客户端分类法选择器:

https://www.c-sharpcorner.com/UploadFile/93cb27/client-side-taxonomy-picker-for-sharepoint-app/

https://blogs.msdn.microsoft.com/richard_dizeregas_blog/2014/03/13/taxonomy-picker-in-sharepoint-provider-hosted-app/

使用脚本编辑器添加了代码,并且该控件仅在“编辑模式”下显示-当我保存页面时,该控件消失并抛出以下错误“ b.get_path不是函数”

尝试了多种组合,但由于在SharePoint Online中相同的代码工作正常,因此看起来像是一个错误。

<link href="https://server/sites/TeamSite/SiteAssets/CodeLibrary/styles/taxonomypickercontrol.css" rel="stylesheet"/>
<script type="text/ecmascript" src="https://server/sites/TeamSite/SiteAssets/CodeLibrary/jquery-1.9.1.js"></script>
<script type="text/ecmascript" src="https://server/sites/TeamSite/SiteAssets/CodeLibrary/taxonomypickercontrol.js"></script>
<script type = "text/javascript"  src = "https://server/sites/TeamSite/SiteAssets/CodeLibrary/taxonomypickercontrol_resources.en.js"></script>
<script type = "text/javascript"  src = "https://server/sites/TeamSite/_layouts/15/sp.core.js" ></script>   
<script type = "text/javascript"  src = "https://server/sites/TeamSite/_layouts/15/sp.runtime.js" ></script>   
<script type = "text/javascript"  src = "https://server/sites/TeamSite/_layouts/15/sp.taxonomy.js" ></script>   

<script type = "text/javascript">

if (myStronglyTypedObj === undefined) {
    var myStronglyTypedObj = {};
}

myStronglyTypedObj = {
    // Object Globals 
    "g": {},
    // Pre-initialization functions ensure scripts SharePoint dependencies are loaded
    "preinit": function() {
        // Load necessary libraries
        SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function() {
            // Register what you need from SharePoint (in this case the sp.runtime)             
            SP.SOD.registerSod('sp.runtime.js', SP.Utilities.Utility.getLayoutsPageUrl('sp.runtime.js'));                                               
            // Register what you need from SharePoint (in this case the term store)             
            SP.SOD.registerSod('sp.taxonomy.js', SP.Utilities.Utility.getLayoutsPageUrl('sp.taxonomy.js'));                                             
            // Load the registered items
            SP.SOD.executeFunc('sp.taxonomy.js', 'SP.Taxonomy.TaxonomySession', myStronglyTypedObj.init());
        });     
    },
    // The main Initialization function
    "init": function() {
        /* Check if SP.Taxonomy actually exists yet
         * PLEASE NOTE that it's common that these objects aren't available, even if you've properly loaded them in the "preinit" function. 
         * This bit of code checks if the object is available, and if it's not, waits for 200ms and then tries again until this object is loaded
         */
        if (SP.Taxonomy) {
            console.log("SP.Taxonomy ready... continuing scripts...");
            myStronglyTypedObj.therest();
        } else {
            console.log("SP.Taxonomy not ready...  set timeout and try again after 200ms");
            setTimeout(myStronglyTypedObj.init, 200);
        }
    },
    "therest": function() {
        // Continue with your code here...
        try {
            var context = new SP.ClientContext()
            $('#taxPickerKeywords').taxpicker({ isMulti: true, allowFillIn: true, termSetId: "63858201-dd9b-46b1-b1bb-b6a054fa7cb7" }, context);
        }
        catch(err) {
            alert(err.message);
        }       
    }
}

 $(document).ready(function(){
    myStronglyTypedObj.preinit();
 });
 </script>  

<div>  
  <input type="hidden" id="taxPickerKeywords" />  
</div> 

1 个答案:

答案 0 :(得分:0)

如前所述,它可以在SharePoint Online中运行,尽管我检查了Farm的版本,并且看来我们的开发箱不是最新的。

修补后,效果很好。

感谢您的宝贵帮助。enter image description here

相关问题