问题
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?
回答1:
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.
If you want to get the same value from your popup, call it on the opener
like this:
opener.$display.getView().getSourceEditorName()
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 });
}
And then read it in your popup's JavaScript using:
var fieldName = window.dialogArguments.fieldName;
来源:https://stackoverflow.com/questions/10209104/how-to-get-the-current-field-name-in-tridion