为什么我的 dojo.byId 不能在脚本库中工作?

发布于 2024-08-16 22:54:27 字数 435 浏览 3 评论 0原文

我有一个带有 dojo 代码的网页,其中包括一个传递给 dojo.addOnLoad 的函数,代码如下:

laborDetailHandler.RevenueTotalInput = dojo.byId('#{id:LaborRevenueTotal}');
if (!laborDetailHandler.RevenueTotalInput) {
 console.warn('RevenueTotalInput not found.')
}

如果此代码是内联的,即使它位于 LaborRevenueTotal 输入框上方,它也可以工作。

如果将此代码移出到脚本库,我会收到“未找到 RevenueTotalInput”。消息,它告诉我 dojo.addOnLoad 接收该函数并执行它,但由于某种原因该函数无法工作。

我完全被难住了。有人有什么想法吗?

I have a web page with dojo code on it, including a function passed to dojo.addOnLoad with the following code:

laborDetailHandler.RevenueTotalInput = dojo.byId('#{id:LaborRevenueTotal}');
if (!laborDetailHandler.RevenueTotalInput) {
 console.warn('RevenueTotalInput not found.')
}

If this code is in-line, even if it's above the LaborRevenueTotal inputbox, it works.

If this code is moved out to a script library, I get the 'RevenueTotalInput not found.' message, which tells me that dojo.addOnLoad receives the function and executes it, but for some reason the function isn't working.

I'm completely stumped here. Anyone have any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

往日 2024-08-23 22:54:27

“#{...}”表达式在 SSJS 库中不起作用,仅在 XPage 或自定义控件的源中起作用。

解决方法:在其他任何地方(例如文本字段)使用 #{} 子句,并在客户端脚本中引用它。

'#{...}' expression does not work inside SSJS libraries, only in source of XPage or Custom Control.

Workaround: use #{} clause anywhere else (text field, for example) and refer to it in your client side script.

终难愈 2024-08-23 22:54:27

如果您将代码放入 XPage 上的属性或事件中,它将作为字符串并通过求值器传递。如果您在 Package Explorer 视图中查看为 XPage 创建的 Java 类,您就会明白我的意思。该代码是一个字符串,然后传递给 Java 函数,该函数在页面加载或运行时对其进行计算。

我认为脚本库中的代码不会经过评估器,因此不会计算 #{id:myField}。还有一个上下文问题,从中可以识别渲染的 HTML 页面上的 myField 的含义。

有两种方法可以解决这个问题。一种是将 ID 从 XPage 事件传递到 SSJS / CSJS 函数。 CSJS 中的另一个选项是使用 dojo.query。

If you put code in a property or event on an XPage, it gets passed as a String and through an evaluator. If you look at the Java classes created for your XPages in the Package Explorer view, you'll see what I mean. The code is a String that is then passed to a Java function that evaluates it on page load or at runtime.

I don't think code in the Script Libraries goes through the evaluator, so the #{id:myField} isn't calculated. There is also the issue of the context from which to identify which myField on your rendered HTML page it means.

There are two ways round it. One is to pass the ID into your SSJS / CSJS functions from your XPage events. The other option in CSJS is to use dojo.query.

素手挽清风 2024-08-23 22:54:27

我道歉!我以为这是一个道场问题;相反,这是一个 Lotus Notes XPages 问题!我仍然不确定为什么会发生这种情况,但有人证实了这个问题更大比我的脚本以及如何解决它。

我的解决方法是,不是在脚本库中查找这些元素,而是获取我需要的元素的句柄并将它们传递给脚本库中的初始化函数。

非常感谢佩勒的回复。很抱歉我的问题不好。

I apologize! I thought this was a dojo question; instead it was a Lotus Notes XPages question! I'm still not sure why this is happening, but someone has corroborated the that problem is larger than my script and how to resolve it.

My workaround is, rather than find these elements within the script library, to get handles to the elements I need and pass them to an initialize function within the script library.

Thank you very much peller for responding. I'm sorry my question was bad.

瞳孔里扚悲伤 2024-08-23 22:54:27

虽然 XPages 中没有编译脚本库;它们也不内联运行。

XPage 中的最佳实践是在脚本库中使用黑盒方法。对脚本库中定义的所有函数使用参数化(对服务器端和客户端均有效)。

或者,在 SSJS 中,您可以通过 getComponent 获取组件对象并了解其 client-id,但这会降低脚本库的可重用性。如果您只是为了保持 XSP 代码整洁而使用它们,那也没有问题。但一定要使用错误陷阱(try/catch),因为调试 SSJS 很头疼。

Although script libraries are not compiled in XPages; they also don't run inline.

The best practice in XPages is using black-box approach in script libraries. Use parametrization for all functions defined in script libraries (valid for both server-side and client-side).

In SSJS, alternatively, you may get the component objects by getComponent and learn their client-id's however, this reduces the reusability of script libraries. It's fine if you use them just to keep your XSP code clean; but make sure using error traps (try/catch) because it's an headache to debug SSJS.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文