私はCustomActionを持っており、リボンにボタンを追加しています。私のCommandHandlerは、EnabledScriptを指定して、ボタンの有効/無効を決定します。以下を参照してください:SharePoint 2010 CustomActions:EnabledScriptとexecuteQueryAsync
<CommandUIHandlers>
<CommandUIHandler
Command="CreateSiteGroup"
CommandAction="javascript:CreateCreateSiteGroup();"
EnabledScript="javascript:CreateCreateSiteGroupButtonEnabled();">
</CommandUIHandler>
</CommandUIHandlers>
CreateCreateSiteGroupButtonEnabled()関数はちょうどしかし、私はいくつかのオブジェクトのプロパティを読み込むことができるように、その内部executeQueryAsync機能を使用するために持っていた、真/偽を返す必要があります。明らかに、このメソッドは非同期に実行されるため、true/false値は返されません。
私のコードは次のようになります。
function CreateContributorsGroupButtonEnabled() {
this.clientContext = new SP.ClientContext.get_current();
this.web = this.clientContext.get_web();
this.clientContext.load(this.web, "Title");
this.clientContext.executeQueryAsync(Function.createDelegate(this, this.OnContextSucceeded), Function.createDelegate(this, this.OnQueryFailed));
}
function OnContextSucceeded() {
this.siteGroups = web.get_siteGroups();
this.clientContext.load(this.siteGroups);
this.clientContext.executeQueryAsync(Function.createDelegate(this, this.OnQuerySucceeded), Function.createDelegate(this, this.OnQueryFailed));
}
function OnQuerySucceeded() {
var contributorsGroupTitle = String.format("{0} Contributors", web.get_title());
var siteGroupEnumerator = this.siteGroups.getEnumerator();
while (siteGroupEnumerator.moveNext()) {
var siteGroup = siteGroupEnumerator.get_current();
if (siteGroup.get_title().toLowerCase() == contributorsGroupTitle.toLowerCase())
return false;
}
return true;
}
は、誰もが、私は非同期関数から戻って真/偽を返すことができる方法を知っていますか?または、特定の名前のサイトグループがすでに存在するかどうかを確認するにはを使用しないでくださいexecuteQueryAsync?
ありがとうございますアニタ!このソリューションに関心のある他の人には、 "enableButton"フラグを設定する場所とRefreshCommandUI()をどこで呼び出すかをdemostratesするこのオンラインサンプルを使用しました。 http://social.technet.microsoft.com/Forums/en-US/sharepoint2010programming/thread/9919c211-1121-422c-8f31-389ea39855c0 –