Chr*_*ers 6 tridion tridion-2011
我为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);
};
Run Code Online (Sandbox Code Playgroud)
并且事件处理程序如下所示:
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);
};
Run Code Online (Sandbox Code Playgroud)
这很好,除了变量commentername总是未定义.有没有更好的方法来获取用户的名称和描述?
此外,是否有人知道返回的值eventitem.source.getCreatorId()实际上是Reviser还是实际创建该项目的人?
我通常在安圭拉遵循这种方法:
$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();
}
Run Code Online (Sandbox Code Playgroud)
然后,您将从事件处理程序调用模型的Web服务,因为您确定该对象将被加载.
在您当前的代码中,您可能在加载对象之前尝试读取描述,因此未定义.我倾向于在this.propertiesvar(p在我的例子中)中放置多个函数所需的变量,然后在每个函数的开头执行类似的操作:
var p = this.properties;
var whatever = p.whatever;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
206 次 |
| 最近记录: |