如何在 SDL Tridion Anguilla 框架中从用户的 ID 中获取用户的名称和描述 [英] How do you get a user's name and description from their ID in the SDL Tridion Anguilla framework

查看:20
本文介绍了如何在 SDL Tridion Anguilla 框架中从用户的 ID 中获取用户的名称和描述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为 SDL Tridion 2011 SP1 编写了一个 GUI 扩展.GUI 包含一个额外的功能区按钮和在保存组件时触发的事件处理程序.

I have written a GUI extension for SDL Tridion 2011 SP1. The GUI consists of an extra ribbon button and event handler which is triggered when a component is saved.

我的事件处理程序注册如下:

My event handler is registered as follows:

PowerTools.Commands.ItemCommenting.prototype._execute = function (selection) {
    var item = $display.getItem();
    $evt.addEventHandler(item, "save", this.getDelegate(this._onItemSaved));
    $cme.getCommand("SaveClose")._execute(selection);
};

事件处理程序如下所示:

and the event handler looks like this:

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 始终未定义.有没有更好的方法来获取用户的名称和描述?

This is working fine, except that the variable commentername is always undefined. Is there a better approach for getting the name and description of a user?

另外,有谁知道eventitem.source.getCreatorId()返回的值实际上是Reviser还是创建该项目的人?

Additionally, does anyone know if the value returned by eventitem.source.getCreatorId() is actually the Reviser or actually the person who created the item?

推荐答案

我在安圭拉通常采用这种方法:

I normally follow this approach in Anguilla:

  1. 使用 $models.getItem(item Id) 加载对象,从某人 (@puf?) 那里听说这是缓存的.
  2. 检查 object.isLoaded() 是否存在,如果是,则执行我的事件处理程序
  3. 如果对象未加载,则监听事件
  1. use $models.getItem(item Id) to load objects, heard from someone (@puf?) that this is cached.
  2. check if the object.isLoaded() and if so, execute my event handler
  3. if the object is not loaded, then listen to the event

这一切都归结为这样:

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();
}

然后您将从事件处理程序中调用模型的网络服务,因为您确定届时将加载该对象.

You would then call your model's webservice from the event handler, since you're sure the object will be loaded by then.

在您当前的代码中,您可能试图在加载对象之前阅读描述,因此未定义.我倾向于将多个函数中需要的变量放在 this.properties var(在我的示例中为 p),然后在每个函数的开头执行以下操作:

In your current code you're probably trying to read the description before the object is loaded, hence the undefined. I tend to place variables that I will need across multiple functions in the this.properties var (p in my example) then do something like this at the beginning of every function:

var p = this.properties;
var whatever = p.whatever;

这篇关于如何在 SDL Tridion Anguilla 框架中从用户的 ID 中获取用户的名称和描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆