如何在 Tridion 中获取当前字段名称? [英] How to get the current field name in Tridion?

查看:22
本文介绍了如何在 Tridion 中获取当前字段名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Tridion 2011 SP1 的功能区工具栏中添加了一个按钮.当我单击按钮时,它将打开一个 aspx 页面.在该 aspx 页面内,我需要访问光标当前所在的当前字段名称.请提供我要使用的对象?对于架构名称,我使用了 $display.getView().getItem().getSchemaId().同样有没有办法获取当前的字段名?

I adding a button to the ribbon tool bar in Tridion 2011 SP1. When I click on the button it will open an aspx page.Inside that aspx page I need to access the current field name where the cursor is presently. Please provide me which object to be used? For schema name I used $display.getView().getItem().getSchemaId(). Similarly is there any way to get the current field name?

推荐答案

我得到的最接近的是使用此代码(在组件编辑窗口中):

The closest I got is using this code (in the Component edit window):

$display.getView().getSourceEditorName()

这将返回当前字段的名称,即使方法名称暗示它执行其他操作.

This will return the name of the current field, even though the method name suggests it does something else.

如果您想从弹出窗口中获得相同的值,请在 opener 上调用它,如下所示:

If you want to get the same value from your popup, call it on the opener like this:

opener.$display.getView().getSourceEditorName()

更好的解决方案

与其在弹出窗口中查找字段名称,不如在调用命令时将其作为参数传递到弹出窗口中.您可以从传递给命令的 _execute 方法的 target 参数中获取它.

Better solution

Instead of looking up the field name from within the popup, you should really pass it into your popup as a argument when your command is invoked. You can get it from the target parameter that is passed to the _execute method of your Command.

GUI.Extension.prototype._execute = function GUI$Extension$_execute(target) {
    target.editor.setFocus();
    var fieldName = target.item.getSourceEditorName();
    var popup = $popup.create("/WebUI/Editors/GUI.Extensions/Extension.aspx",
                "width=400px,height=150px,resizable=0",
                { fieldName: fieldName });
}

然后在弹出窗口的 JavaScript 中使用:

And then read it in your popup's JavaScript using:

var fieldName = window.dialogArguments.fieldName;

这篇关于如何在 Tridion 中获取当前字段名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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