[英]Script editor working only in edit page mode
在編輯頁面模式下,腳本可以正常工作,但是當我停止編輯頁面時,腳本將無法運行。
<script language='javascript' type='text/javascript'>
function FilterOMenu(c, a) {
//Be carefull with overriding SharePoint core functions, for now this will work (September 2016 CU). Ensure you test this every time after installing a SharePoint update.
//SharePoint default (I placed this above, cause it returns.)
if (a == null)
return;
var b = a.tagName == "DIV" ? a.parentNode : a;
//End SharePoint default
//Custom implementation to sort the filter
var fieldInternalName = a.getAttribute("name");
//some sort functions
var ascComparer = function(a,b){return a.text<b.text ? -1:a.text>b.text ? 1 : 0;};
var descComparer = function(a,b){return a.text>b.text ? -1:a.text<b.text ? 1 : 0;};
var ascDateComparer = function(a,b){d1 = Date.parse(a.text);d2 = Date.parse(b.text);return d1<d2 ? -1:d1>d2 ? 1 : 0;};
var descDateComparer = function(a,b){d1 = Date.parse(a.text);d2 = Date.parse(b.text);return d1>d2 ? -1:d1<d2 ? 1 : 0;};
var myCustomSort = {};
//Add the field internal name and give a comparer as value to sort
//As example the title column as your case is
myCustomSort["Kuup_x00e4_ev"] = descDateComparer;
//myCustomSort["Aktiivne"] = ascComparer;
//console.log(myCustomSort["Date"]);
if(typeof c != "undefined" && c != null && typeof myCustomSort[fieldInternalName] != "undefined"){//check if you implemented a custom sort for the current internalname
//select all items that are checkable (the options)
var allSelectableItems = c.querySelectorAll('[checked]');
if(allSelectableItems.length > 0){
var elementInnerhtmls = [];
var htmlToReplace = "";
var htmlToAppend = "";
for(var i = 0;i<allSelectableItems.length;i++)
{
elementInnerhtmls.push({text: allSelectableItems[i].getAttribute("text"),html:allSelectableItems[i].outerHTML});
htmlToReplace += allSelectableItems[i].outerHTML;
}
elementInnerhtmls = elementInnerhtmls.sort(myCustomSort[fieldInternalName]);
for(var i = 0;i<elementInnerhtmls.length;i++)
{
htmlToAppend += elementInnerhtmls[i].html;
}
//replace the original html with the sorted html
c.innerHTML = c.innerHTML.replace(htmlToReplace,htmlToAppend);
}
}
//SharePoint default
OMenu(c, b, null, null, -1)
//End SharePoint default
} </script>
我有語言和類型屬性設置,但仍然沒有。 有人可以告訴我為什么我的發布頁面腳本只在我去編輯頁面時運行?
如果出現以下情況,通常會發生此問題:
type=”text/javascript”
。 “SP.js”
和“SP.Runtime”
文件未正確“SP.Runtime”
。 ExecuteOrDelayUntilScriptLoaded
函數。 Minimal Download Strategy Feature
已激活。 有關更多詳細信息,請查看SharePoint 2016:JSOM僅在編輯模式下工作
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.