且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 Tridion 中获取当前字段名称?

更新时间:2023-02-18 23:37:21

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

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;