![](/img/trans.png)
[英]How to GetLocalizedItems using Tridion Anguilla Framework?
[英]How do you get a user's name and description from their ID in the SDL Tridion Anguilla framework
我為SDL Tridion 2011 SP1編寫了一個GUI擴展。 GUI由一個額外的功能區按鈕和事件處理程序組成,該功能處理程序在保存組件時觸發。
我的事件處理程序注冊如下:
PowerTools.Commands.ItemCommenting.prototype._execute = function (selection) {
var item = $display.getItem();
$evt.addEventHandler(item, "save", this.getDelegate(this._onItemSaved));
$cme.getCommand("SaveClose")._execute(selection);
};
並且事件處理程序如下所示:
PowerTools.Commands.ItemCommenting.prototype._onItemSaved = function (eventitem) {
var comment = prompt("Please enter a comment", "");
$messages.registerNotification("Saving user comments...");
var commentitemid = eventitem.source.getId();
var commenterid = eventitem.source.getCreatorId();
var commenter = $tcm.getItem(commenterid);
var commentername = commenter.getDescription();
var commentdate = eventitem.source.getLastModifiedDate();
var commentversion = eventitem.source.getVersion();
//Call the service to update
PowerTools.Model.Services.AppDataServices.Append("ext:ItemCommenting", commentitemid, "<comment><user>" + commenterid + "</user><message>" + comment + "</message><datetime>" + commentdate + "</datetime><version>" + commentversion + "</version></comment>", null, null, null, false);
};
這很好,除了變量commentername
總是未定義。 有沒有更好的方法來獲取用戶的名稱和描述?
另外,有人知道eventitem.source.getCreatorId()
返回的值實際上是eventitem.source.getCreatorId()
還是實際創建項目的人?
我通常在安圭拉遵循這種方法:
$models.getItem(item Id)
加載對象,從某人(@puf?)聽到這是緩存的。 這一切都歸結為這樣的事情:
p.keyword = $models.getItem(p.keywordUri);
if (p.keyword.isLoaded()) {
this._onReleaseKeywordLoaded();
} else {
$evt.addEventHandler(p.keyword, "load", this.getDelegate(this._onReleaseKeywordLoaded));
p.keyword.load();
}
然后,您將從事件處理程序調用模型的Web服務,因為您確定該對象將被加載。
在您當前的代碼中,您可能在加載對象之前嘗試讀取描述,因此未定義。 我傾向於在this.properties
var(我的例子中為p
中放置多個函數所需的變量,然后在每個函數的開頭執行類似的操作:
var p = this.properties;
var whatever = p.whatever;
正如Nuno所說,你可能正在閱讀一個尚未裝載的房產。
但是,您不應該接受客戶發送的名稱。 您應該在Web服務中獲取當前用戶的ID和名稱。 其他一些論據也是如此,比如日期/時間。
基本上,您的Web服務永遠不應該信任傳入的數據。 因此,它本身可以解決的任何事情都不應該成為該方法的參數,並且它所需要的任何東西都應該被視為惡意內容並在使用之前進行消毒。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.