在内部部署SharePoint 2013上,使用以下博客为SharePoint实施客户端分类法选择器:
https://www.c-sharpcorner.com/UploadFile/93cb27/client-side-taxonomy-picker-for-sharepoint-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>