0
我的javascript不是最好的,並想知道是否有人可以幫我解決這個問題。本質上,我有一個名爲PGCount的整數列的庫,我希望能夠點擊這個按鈕,它增加了定義變量pgcount的值,它目前是警報,但我有更大的計劃,如果只是爲了獲得預期的結果。Ribbon命令讀取值
可悲的是它計數第一個項目兩次。
這裏是整個模塊
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
Id="Ribbon.Library.Actions.AddAButton"
Location="CommandUI.Ribbon"
RegistrationId="101"
RegistrationType="List"
Title="PGCount">
<CommandUIExtension>
<CommandUIDefinitions>
<CommandUIDefinition
Location="Ribbon.Library.Share.Controls._children">
<Button Id="Ribbon.Library.Share.NewRibbonButton"
Command="CountPGCount"
LabelText="Page Count"
TemplateAlias="o2" />
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<CommandUIHandler Command="CountPGCount"
CommandAction="javascript:
var listitem;
var pgcounts = 0;
getWebProperties();
function getWebProperties() {
var ctx = new SP.ClientContext.get_current();
var currentWeb = ctx.get_web();
var currentListGuid = SP.ListOperation.Selection.getSelectedList();
var currentList = currentWeb.get_lists().getById(currentListGuid);
var selectedItems = SP.ListOperation.Selection.getSelectedItems();
for (i in selectedItems) {
listitem = currentList.getItemById(selectedItems[i].id);
ctx.load(listitem);
ctx.executeQueryAsync(Function.createDelegate(listitem, function() {
var c = listitem.get_fieldValues().PGCount;
pgcounts+=c;
}), null);
};}
setTimeout(function() {
alert(pgcounts);
}, 3000);"
EnabledScript="javascript:SP.ListOperation.Selection.getSelectedItems().length >= 1;" />
</CommandUIHandlers>
</CommandUIExtension>
</CustomAction>
<Module Name="Module1">
</Module>
</Elements>
任何幫助,將不勝感激!