为什么 Magento 中的原型代码会崩溃?

发布于 2024-09-24 02:10:41 字数 867 浏览 3 评论 0原文

在过去的一个半小时里,我在我正在构建的 Magento 商店中跟踪了 Javascript 调用,因为我有一个奇怪的效果,即结账时,我无法留下单页结账的第 2 页(送货地址),除非我从“发送到这个地址”切换到“发送到另一个地址”。

我已经将其追溯到 form.js 中的这段 javascript 代码,位于 Regionupdater.setMarkDisplay (第 254 行以下)。

由于我自己是一个 jquery 人,所以我并没有真正参与原型功能的循环,但我'我假设 .up 和 .down 实际上就是 jquery 对 .parent(s) 和 .children() 所做的事情?!

elem = $(elem);
var labelElement = elem.up(0).down('label > span.required') ||
                   elem.up(1).down('label > span.required') ||
                   elem.up(0).down('label.required > em') ||
                   elem.up(1).down('label.required > em'); 

elem 是表单中的区域选择字段。 我假设它正在尝试查找该字段的标签(存在)。但两个“elem.up(0)”片段显然都会抛出一个“

[Exception... "An invalid or illegal string was specified" code: "12" nsresult: "0x8053000c (NS_ERROR_DOM_SYNTAX_ERR)"]

我不知道是什么触发了这个”。

For the last hour and a half I've trace Javascript calls in a Magento shop I'm building, because I have the strange effect that, when checking out, I can not leave page 2 (shipping address) of the onepage checkout, unless I switch from "send to this address" to "send to another address".

I've traced it down to this piece of javascript code in form.js, residing in Regionupdater.setMarkDisplay (line 254 ff.)

Since I'm a jquery man myself I'm not really in the loop with prototype functionality but I'm assuming .up and .down are practically what jquery does with .parent(s) and .children()?!

elem = $(elem);
var labelElement = elem.up(0).down('label > span.required') ||
                   elem.up(1).down('label > span.required') ||
                   elem.up(0).down('label.required > em') ||
                   elem.up(1).down('label.required > em'); 

elem is the region select field in the form.
I'm assuming it's trying to find the label for this field (which exists). But both the "elem.up(0)" fragments apparently throw an

[Exception... "An invalid or illegal string was specified" code: "12" nsresult: "0x8053000c (NS_ERROR_DOM_SYNTAX_ERR)"]

I've no idea what triggers this.

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

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

发布评论

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

评论(2

夏天碎花小短裙 2024-10-01 02:10:41

您基本上对 up 和 < a href="http://api.prototypejs.org/dom/element/down/" rel="nofollow noreferrer">down 即可。该行代码正在选择第一个匹配元素:

elem = $(elem);
var labelElement = elem.up(0).down('label > span.required') || // Up to parent, down to first span.required inside a label
                   elem.up(1).down('label > span.required') || // Up to grandparent, down to first span.required inside a label
                   elem.up(0).down('label.required > em') ||   // up to parent, down to first em inside a label.required
                   elem.up(1).down('label.required > em');     // up to grandparent, down to em within a label.required

...在每种情况下,它都会在找到的第一个元素处停止。

该错误看起来像是从选择器引擎抛出的,或者是传递给它不理解的选择器的东西。这些选择器都不是特别前沿,所以这有点奇怪。您使用的是 Prototype 1.7 RC2 吗?因为当前发布的Prototype仍然只使用自己内置的选择器引擎(而1.7添加了可插入的选择器引擎)。

啊!就是这样 - 查看该区域中元素的 id。它们中是否有空格或“#”或“:”之类的东西?我似乎记得原型选择器引擎中的一个错误,它假设相当无聊的ID...(为什么ID是相关的?在幕后,选择器引擎可能在处理后代或子选择器时使用它们——例如,在处理< code>down 调用...)

更新 这个(已修复)错误可能与此相关,如果您使用的是旧版本的 Prototype,您可能仍然会遇到它。绝对值得一看 ID。

You're basically right about what up and down do. That line of code is picking the first matching element:

elem = $(elem);
var labelElement = elem.up(0).down('label > span.required') || // Up to parent, down to first span.required inside a label
                   elem.up(1).down('label > span.required') || // Up to grandparent, down to first span.required inside a label
                   elem.up(0).down('label.required > em') ||   // up to parent, down to first em inside a label.required
                   elem.up(1).down('label.required > em');     // up to grandparent, down to em within a label.required

...where in each case it stops with the first one it finds.

The error looks like it's being thrown from a selector engine or something being passed a selector it doesn't understand. None of those selectors is particularly cutting-edge, so that's a bit strange. Are you using Prototype 1.7 RC2? Because the current released Prototype still only uses its own built-in selector engine (whereas 1.7 adds pluggable ones).

Ah! That's it -- look at the ids of the elements in that area. Do any of them have spaces or '#' or ':' in them, that sort of thing? I seem to recall a bug in the Prototype selector engine where it assumes fairly boring IDs... (Why are IDs relevant? Under the covers, the selector engine may use them when processing descendant or child selectors -- for instance, when processing down calls...)

Update This (fixed) bug may relate to this, if you're using an older version of Prototype you may still be running into it. Definitely worth looking at the IDs.

我ぃ本無心為│何有愛 2024-10-01 02:10:41

我在 IE8 上有同样的错误,但就我而言,这不是因为未转义的冒号。我遇到错误是因为我使用的是修改 DOM 的自定义主题,因此 elem.up(0) 指向其他元素。
您应该查看 Skin/frontend/your_template/js/opcheckout.js 第 420 行和 428 行
函数 setSameAsBilling 和syncWithBilling 或更改您的模板文件 - Shipping.phtml。
此外,在默认皮肤上也不会出现此错误。

I have the same error, on IE8, but in my case it's not because of unescaped colon. I have the error because I'm using a custom theme that modified the DOM so elem.up(0) is pointing to other element.
You should look at skin/frontend/your_template/js/opcheckout.js at lines 420 and 428
functions setSameAsBilling and syncWithBilling or change your template file - shipping.phtml.
Also on default skin this error does not apear.

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