如何在 Tridion 的 CME 中处理视图的加载 [英] How to handle loading of a view in Tridion's CME

查看:20
本文介绍了如何在 Tridion 的 CME 中处理视图的加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Tridion 2011 Content Manager Explorer 的扩展,我想在其中只为特定视图执行特定的 JavaScript 片段.

I have an extension to the Tridion 2011 Content Manager Explorer where I want to execute a specific piece of JavaScript only for a specific view.

我使用以下 JavaScript 片段执行此操作:

I do this with the following JavaScript fragment:

var onDisplayStarted = function () {
    $evt.removeEventHandler($display, "start", onDisplayStarted);

    if ($display.getView().getId() == "PublishPopup") {
      ...
    }
};
$evt.addEventHandler($display, "start", onDisplayStarted);

这段代码过去运行良好,它肯定会在 PublishPopup 打开时触发,并确保我的代码仅在该特定视图中执行.

This code has worked well in the past and it definitely triggers when the PublishPopup opens and ensures my code only executes in that specific view.

但不幸的是,我有时会在加载 DashboardView 时在 JavaScript 控制台中收到以下错误消息:

But unfortunately I sometimes get the following error message in the JavaScript console while loading the DashboardView:

Uncaught TypeError: Object # has no method 'getId'

Uncaught TypeError: Object # has no method 'getId'

该错误不会导致任何问题,很可能是因为 Tridion 的 UI 框架正确处理了事件处理程序中的错误.但我仍然希望在 JavaScript 控制台中不显示错误.

The error doesn't cause any problems, most likely since errors in event handlers are handled correctly by Tridion's UI framework. But I'd still prefer to not have the error showing in the JavaScript console.

我了解如何检测 getId 方法是否存在:

I understand how to detect if the getId method exists:

if ($display.getView().getId && $display.getView().getId() == "PublishPopup") {

但这只是意味着代码永远不会执行.尽管它现在在 PublishPopup 中似乎运行良好,但我更想知道处理这种视图初始化后应执行我的代码"序列的正确方法.

But that would just mean that the code doesn't execute ever. And although it seems to work fine in the PublishPopup right now, I'd rather know the proper way to handle this type of "my code should execute once the view has initialized" sequence.

有没有人知道处理这个问题的更好方法?

Does anyone know a better way to handle this?

推荐答案

好吧,有两个不同的视图,它们是同时加载的——Dashboard View 和 Tridion Dashboard View.当您单击功能区工具栏中的 SDL Tridion 选项卡时,您会看到 Tridion 仪表板视图.事实上,这个视图没有 getId 方法(这很奇怪,顺便说一句).这就是您遇到此问题的原因.

Well, there are two different views, which are loaded at the same time - Dashboard View and Tridion Dashboard View. Tridion Dashboard View is what you see when you click on SDL Tridion tab in Ribbon Toolbar. Indeed, this view doesn't have getId method (which is strange, btw). That's why you have this issue.

尽管如此,配置文件中的文件组背后的整个想法是最大限度地减少为每个视图加载的 javascript 数量,并最大限度地减少不需要的 javascript 处理.因此,我建议将您的 javascript 文件拆分为多个部分,并仅在必要时加载它们.

Nevertheless, the whole idea behind the file groups in configuraton file is to minimize amount of the javascript, loaded for each view and to minimize un-needed javascript processing. So I would recommend to split your javascript file into pieces and load them only oт necessity.

这篇关于如何在 Tridion 的 CME 中处理视图的加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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