该代码将自定义图标添加到SharePoint功能区。即使修改了XML,也无法一遍又一遍地重新部署图标,而无法更新已部署的功能区。
我试图调整XML ExecuteOrDelayUntilScriptLoaded(init_HideButton,“ sp.ribbon.js”); SP.SOD.executeOrDelayUntilScriptLoaded(AddCustomUserAction,“ sp.js”);
DF$Var3 = with(DF,
ifelse(Var2 == 1, Var1 * 30,
ifelse(Var2 == 2, Var1 * 4,
ifelse(Var2 == 3, Var1, NA))))
该代码一遍又一遍地重新部署功能区中的图标,并且不重新部署就无法更改警报。
答案 0 :(得分:0)
尝试以下脚本。
Modifying a User Custom Action Using JavaScript
var siteUrl = '/sites/MySiteCollection';
function modifyUserCustomAction() {
this.clientContext = new SP.ClientContext(siteUrl);
var oWebsite = clientContext.get_web();
this.oList = oWebsite.get_lists().getByTitle('My List');
this.collUserCustomAction = oList.get_userCustomActions();
clientContext.load(oList,'UserCustomActions','Title');
clientContext.executeQueryAsync(Function.createDelegate(this, this.SetImage), Function.createDelegate(this, this.onQueryFailed));
}
function SetImage() {
var customActionEnumerator = collUserCustomAction.getEnumerator();
while (customActionEnumerator.moveNext())
{
var oUserCustomAction = customActionEnumerator.get_current();
if (oUserCustomAction.get_title() == 'My First User Custom Action')
{
oUserCustomAction.set_imageUrl('http://MyServer/_layouts/images/MyIcon.png');
oUserCustomAction.update();
clientContext.load(oUserCustomAction);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
}
}
function onQuerySucceeded() {
alert('Custom action changed for ' + this.oList.get_title());
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
答案 1 :(得分:0)
通过功能区中的新图标运行JavaScript函数的答案只是通过SP设计器或代码中的userActionExtension变量即可完成。就我而言,我已经在页面上的内容编辑器Web部件中创建了一个函数,然后通过SP设计器(导航至URL窗口)对其进行了引用:JavaScript:GetItemId();
如Lee_MSFT条目中所述,图标在功能区中的部署保持不变。
谢谢