【发布时间】:2012-07-19 18:08:06
【问题描述】:
我需要从任何 Tridion 页面的 Component Presentation 选项卡中获取 Component 和 Component Template tcm id。
场景:
- 在 Tridion 的现有页面上。
- 转到“组件演示”选项卡。
- 当我单击“插入”按钮时,我想迭代组件和组件模板 tcm id 并将其显示在 JavaScript 警报框中。
我正在尝试找到确切的 javascript 文件/函数来完成此操作,但我找不到确切的。
我正在使用 SDL Tridion 2011 SP1。
任何帮助/建议将不胜感激。
编辑
我有这个脚本,当我们单击“插入组件演示”窗口中的“插入”按钮时会触发该脚本。
Tridion.Cme.Views.InsertCpDialog.prototype.onInsertClick =
function InsertCpDialog$onInsertClick()
{
var p = this.properties;
var c = p.controls;
var templateId = c.templateSelect.getValue();
var components = c.list.getSelection().getItems();
p.componentPresentationsAdded += components.length;
var compId = components[components.length - 1];
var component = $models.getItem(compId);
if (component)
{
var userSettings = Tridion.UI.UserSettings.getInstance();
if (userSettings && userSettings.isLoaded())
{
Tridion.UI.UserSettings.setLastSelectedLocation(
component.getPublicationId(), $const.ItemType.COMPONENT, p.contextUri);
}
}
this.fireEvent("insert", {
components: components,
template: templateId
});
};
所以这里我将获取所选组件的tcm id和要插入的模板“compId”和“templateId”。现在我的问题是:如何检查此组件和模板是否已经存在于组件演示选项卡上?
如果我能够以某种方式获取页面上已经存在的所有组件和模板的 ID(通过我的“插入”按钮),那么我可以比较它们。但是我没有得到任何可以给我这些ID的功能。我在这里卡住了。
编辑
我正在尝试使用这些代码进入页面,但我无法获得正确的函数,该函数在单击插入时被触发,或者将返回那里列出的组件列表和模板 ID。
Extensions.Test.prototype.isEnabled = function Test$isEnabled(selection) {
try
{
console.log($controls);
var masterTabControl = $controls.getControl($("#MasterTabControl"),
"Tridion.Controls.TabControl");
console.log(masterTabControl);
alert("Mastercontrol - ComponentpresentationsTab");
console.log(masterTabControl.getPage("ComponentPresentationsTab"));
console.log("list of component presentations");
console.log(masterTabControl.getPage("ComponentPresentationsTab").
getListComponentPresentations().getItems());
console.log("list of get xml");
console.log(masterTabControl.getPage ("ComponentPresentationsTab").
getListComponentPresentations().getItems().getXml);
}
(catch exc)
{
}
return true;
}
编辑 我使用此代码获得了 CP TAB 下列出的所有 CP Id。感谢@Frank van Puffelen
var p = this.properties;
var tgp = this.properties;
var c = p.controls;
var pageId = selection.getItem(0);
var masterTabControl = $controls.getControl($("#MasterTabControl"),
"Tridion.Controls.TabControl");
var compPresTab = masterTabControl.getPage("ComponentPresentationsTab");
var comPresList = p.compPresTab.getListComponentPresentations();
for (var i = 0; i <= myStringArray.length; i++)
{
console.log(comPresList.getItems()[i].getComponentId());
console.log(comPresList.getItems()[i].getComponentTemplateId());
}
【问题讨论】:
-
您向我们展示您已经编写的代码以及您遇到的问题如何?
-
可能重复[如何编写c程序来添加按钮](stackoverflow.com/questions/11446313/…)
-
如果您不提供有关您已完成的操作的更多信息,您很有可能会锁定此用户帐户提出类似于@user1518281 的问题。 Stack Overflow 并不意味着将您的需求列表转换为可以复制/粘贴到解决方案中的工作代码。我们可以帮助您完成您的工作,但前提是您向我们展示您已经完成的工作。
-
这段代码是你写的吗?看起来你复制了标准的
InsertCpDialog.onInsertClick方法。你明白这段代码的作用吗?如果没有:您是否在其中设置了断点并单步执行?您将看到它可以访问包含视图中所有控件的controls数组(在本例中为InsertCpDialog弹出窗口)。此逻辑适用于任何视图,因此您只需跟随线索即可。 -
不,我没有说我写这段代码。我在调试站点并搜索单击“插入”(在 InsertCpDialog 弹出窗口上)按钮时触发的功能时得到了这个。因此,我尝试对页面上 CP 选项卡下的“插入”按钮执行相同的操作。所以我想深入了解
标签: tridion tridion-2011