2017-08-25 74 views
-1

我一直在開發SharePoint的擴展。我試圖爲文檔庫實現自定義標註(使用fancytree進行庫內容呈現)。 僅供參考我已使用https://dev.office.com/sharepoint/docs/sp-add-ins/highlight-content-and-enhance-the-functionality-of-sharepoint-hosted-sharepointSharepoint 2013標註未定義

我已經在單獨的函數execCallout(data)中定義了調用函數。 (爲了簡單起見,省略了具有數據的功能)。

我有兩種情況:execCallout由用戶啓動/調用(無預裝數據),並且execCallout加載了啓動數據。在這兩種情況下,我使用相同的execCallout。

function execCallout (data) { 
console.log("demo"); 
//get our launchpoint - where callout will appear 
var targetElement = document.querySelectorAll(".fancytree-active.fancytree-focused .fancytree-title")[0]; 


//Configure new Callout 
var calloutOptions = new CalloutOptions(); 
calloutOptions.ID = 'MyCustomCallOut'; 
calloutOptions.launchPoint = targetElement; 
calloutOptions.beakOrientation = 'leftRight'; 
calloutOptions.content = ' My Content'; 
calloutOptions.title = 'My Title'; 

// check for current callout 
var myCallOut = CalloutManager.createNewIfNecessary(calloutOptions); 

//Create custom action for callout 
var myAction = new CalloutActionOptions(); 
myAction.text = 'My Special Action'; 
myAction.onClickCallback = function(event, action) 
{ 
    alert("I can do whatever you want"); 
}; 

var newAction = new CalloutAction(myAction); 

//Add the action to the callout 
myCallOut.addAction(newAction); 
myCallOut.set({ openOptions: { event: "hover" } }); //or click 
myCallOut.open(); 

}

第一個方案正常工作,即,在用戶點擊後標註啓動/ execCallout被調用。但是,當預加載數據時,我得到「未捕獲的ReferenceError:myCallOut沒有定義」(從調試器控制檯我看到該函數被調用,但是calloutManager沒有與我的launchPoint關聯的調用)。看起來好像calloutManager沒有啓動。 任何時候從調試器控制檯啓動execCallout都可以解決問題。

想法是什麼以及在哪裏失蹤是值得歡迎的。

回答

0

我的問題是:問題是由fancytree渲染造成的。標註在「樹」未完全渲染時發起。默認情況下,在渲染過程中值「丟失」,因此默認的樹渲染導致問題。

解決方案:在標註操作之前手動啓動樹渲染,以避免值/變量消失。