我正面臨一個奇怪的問題。我的Drupal網站使用Jquery 1.4.4版本。jQuery解釋錯了嗎?或Drupal輸出錯誤?
大家都知道,Drupal的輸出Drupal.settings
JSON以JavaScript作爲:
當我使devel_themer
模塊:
以下是輸出
jQuery.extend(Drupal.settings, {
"basePath":"\/d7\/",
"pathPrefix":"",
"ajaxPageState":{
"theme":"bartik",
"theme_token":"KC2-1Z9CN5PCxDyAq_W8FGBQBOOnwt8AyoeX1UDBoP8",
"js":{
"misc\/jquery.js":1,
"misc\/jquery.once.js":1,
"misc\/drupal.js":1,
"misc\/ui\/jquery.ui.core.min.js":1,
"misc\/ui\/jquery.ui.widget.min.js":1,
"misc\/jquery.cookie.js":1,
"misc\/jquery.form.js":1,
"misc\/ui\/jquery.ui.mouse.min.js":1,
"misc\/ui\/jquery.ui.draggable.min.js":1,
"misc\/ui\/jquery.ui.resizable.min.js":1,
"misc\/jquery.ba-bbq.js":1,
"modules\/overlay\/overlay-parent.js":1,
"misc\/ajax.js":1,
"misc\/progress.js":1,
"sites\/all\/modules\/devel_themer\/devel_themer.js":1,
"sites\/all\/modules\/devel\/krumo\/krumo.js":1,
"modules\/toolbar\/toolbar.js":1,
"sites\/all\/modules\/devel\/devel_krumo_path.js":1
},
"css":{
"modules\/system\/system.base.css":1,
"modules\/system\/system.menus.css":1,
"modules\/system\/system.messages.css":1,
"modules\/system\/system.theme.css":1,
"misc\/ui\/jquery.ui.core.css":1,
"misc\/ui\/jquery.ui.theme.css":1,
"misc\/ui\/jquery.ui.resizable.css":1,
"modules\/overlay\/overlay-parent.css":1,
"modules\/comment\/comment.css":1,
"modules\/field\/theme\/field.css":1,
"modules\/node\/node.css":1,
"modules\/search\/search.css":1,
"modules\/user\/user.css":1,
"sites\/all\/modules\/devel_themer\/devel_themer.css":1,
"sites\/all\/modules\/devel\/krumo\/skins\/default\/skin.css":1,
"modules\/shortcut\/shortcut.css":1,
"modules\/toolbar\/toolbar.css":1,
"sites\/all\/modules\/devel_themer\/devel_themer_ie_fix.css":1,
"themes\/bartik\/css\/layout.css":1,
"themes\/bartik\/css\/style.css":1,
"themes\/bartik\/css\/colors.css":1,
"themes\/bartik\/css\/print.css":1,
"themes\/bartik\/css\/ie.css":1,
"themes\/bartik\/css\/ie6.css":1
}
},
"thmrStrings":{
"themer_info":"Themer info",
"toggle_throbber":" \u003Cimg src=\u0022\/d7\/sites\/all\/modules\/devel_themer\/loader-little.gif\u0022 alt=\u0022loading\u0022 class=\u0022throbber\u0022 width=\u002216\u0022 height=\u002216\u0022 style=\u0022display:none\u0022 \/\u003E",
"parents":"Parents: ",
"function_called":"Function called: ",
"template_called":"Template called: ",
"candidate_files":"Candidate template files: ",
"preprocessors":"Preprocess functions: ",
"processors":"Process functions: ",
"candidate_functions":"Candidate function names: ",
"drupal_api_docs":"link to Drupal API documentation",
"source_link_title":"link to source code",
"function_arguments":"Function Arguments",
"template_variables":"Template Variables",
"file_used":"File used: ",
"duration":"Duration: ",
"api_site":"http:\/\/api.drupal.org\/",
"drupal_version":"7",
"source_link":"\/d7\/devel\/source?file="
},
"thmr_popup":" \u003Cdiv id=\u0022themer-fixeder\u0022\u003E\n \u003Cdiv id=\u0022themer-relativer\u0022\u003E\n \u003Cdiv id=\u0022themer-popup\u0022\u003E\n \u003Cdiv class=\u0022topper\u0022\u003E\n \u003Cspan class=\u0022close\u0022\u003EX\u003C\/span\u003E Drupal Themer Information\n \u003C\/div\u003E\n \u003Cdiv id=\u0022parents\u0022 class=\u0022row\u0022\u003E\n\n \u003C\/div\u003E\n \u003Cdiv class=\u0022info row\u0022\u003E\n \u003Cdiv class=\u0022starter\u0022\u003EClick on any element to see information about the Drupal theme function or template that created it.\u003C\/div\u003E\n \u003Cdl\u003E\n \u003Cdt class=\u0022key-type\u0022\u003E\n\n \u003C\/dt\u003E\n \u003Cdd class=\u0022key\u0022\u003E\n\n \u003C\/dd\u003E\n \u003Cdiv class=\u0022used\u0022\u003E\n \u003C\/div\u003E\n \u003Cdt class=\u0022candidates-type\u0022\u003E\n\n \u003C\/dt\u003E\n \u003Cdd class=\u0022candidates\u0022\u003E\n\n \u003C\/dd\u003E\n\n \u003Cdt class=\u0022preprocessors-type\u0022\u003E\n\n \u003C\/dt\u003E\n \u003Cdd class=\u0022preprocessors\u0022\u003E\n\n \u003C\/dd\u003E\n \u003Cdt class=\u0022processors-type\u0022\u003E\n\n \u003C\/dt\u003E\n \u003Cdd class=\u0022processors\u0022\u003E\n\n \u003C\/dd\u003E\n \u003Cdiv class=\u0022duration\u0022\u003E\u003C\/div\u003E\n \u003C\/dl\u003E\n \u003C\/div\u003E\u003C!-- \/info --\u003E\n \u003Cdiv class=\u0022attributes row\u0022\u003E\n \u003Cdiv class=\u0022themer-variables\u0022\u003E\u003C\/div\u003E\n \u003C\/div\u003E\u003C!-- \/attributes --\u003E\n \u003C\/div\u003E\u003C!-- \/themer-popup --\u003E\n \u003C\/div\u003E\n \u003C\/div\u003E",
"overlay":{
"paths":{
"admin":"node\/*\/edit\nnode\/*\/delete\nnode\/*\/revisions\nnode\/*\/revisions\/*\/revert\nnode\/*\/revisions\/*\/delete\nnode\/add\nnode\/add\/*\noverlay\/dismiss-message\nuser\/*\/shortcuts\nadmin\nadmin\/*\nbatch\ntaxonomy\/term\/*\/edit\nuser\/*\/cancel\nuser\/*\/edit\nuser\/*\/edit\/*\ndevel\/*\nnode\/*\/devel\nnode\/*\/devel\/*\ncomment\/*\/devel\ncomment\/*\/devel\/*\nuser\/*\/devel\nuser\/*\/devel\/*\ntaxonomy\/term\/*\/devel\ntaxonomy\/term\/*\/devel\/*",
"non_admin":"admin\/structure\/block\/demo\/*\nadmin\/reports\/status\/php"
},
"pathPrefixes":[
],
"ajaxCallback":"overlay-ajax"
},
"tableHeaderOffset":"Drupal.toolbar.height"
});
,並在瀏覽器控制檯,正如你在下面截圖中看到的Drupal.settings
對象有一些奇怪的對象。
這有什麼奇怪的?
如果我在控制檯中寫入Drupal.settings.thmrStrings
,它表示未定義。但根據上述的對象,應該有。根據json,它顯示生成了一些奇怪的對象,例如Drupal.settings.thmr_1
,Drupal.settings.thmr_2
,Drupal.settings.thmr_3
.. Drupal.settings.thmr_94
,而不是顯示這些有意義的對象。這些Drupal.settings.thmr_*
對象來自哪裏?他們不在JSON中?爲什麼對象不符合jSON?
您在截圖中看到的錯誤是由於此原因而導致的。 javascript文件devel_themer.js
正在訪問Drupal.settings.thmrStrings
的子對象,但它沒有得到它。這是我爲什麼背後的主要問題。
當我禁用devel_themer
模塊:
以下是輸出:
<script type="text/javascript">
<!--//--><![CDATA[//><!--
jQuery.extend(Drupal.settings, {
"basePath":"\/d7\/",
"pathPrefix":"",
"ajaxPageState":{
"theme":"bartik",
"theme_token":"KC2-1Z9CN5PCxDyAq_W8FGBQBOOnwt8AyoeX1UDBoP8",
"js":{
"misc\/jquery.js":1,
"misc\/jquery.once.js":1,
"misc\/drupal.js":1,
"misc\/ui\/jquery.ui.core.min.js":1,
"misc\/jquery.ba-bbq.js":1,
"modules\/overlay\/overlay-parent.js":1,
"modules\/contextual\/contextual.js":1,
"misc\/jquery.cookie.js":1,
"sites\/all\/modules\/devel\/devel_krumo_path.js":1,
"modules\/toolbar\/toolbar.js":1
},
"css":{
"modules\/system\/system.base.css":1,
"modules\/system\/system.menus.css":1,
"modules\/system\/system.messages.css":1,
"modules\/system\/system.theme.css":1,
"misc\/ui\/jquery.ui.core.css":1,
"misc\/ui\/jquery.ui.theme.css":1,
"modules\/overlay\/overlay-parent.css":1,
"modules\/contextual\/contextual.css":1,
"modules\/comment\/comment.css":1,
"modules\/field\/theme\/field.css":1,
"modules\/node\/node.css":1,
"modules\/search\/search.css":1,
"modules\/user\/user.css":1,
"modules\/shortcut\/shortcut.css":1,
"modules\/toolbar\/toolbar.css":1,
"themes\/bartik\/css\/layout.css":1,
"themes\/bartik\/css\/style.css":1,
"themes\/bartik\/css\/colors.css":1,
"themes\/bartik\/css\/print.css":1,
"themes\/bartik\/css\/ie.css":1,
"themes\/bartik\/css\/ie6.css":1
}
},
"overlay":{
"paths":{
"admin":"node\/*\/edit\nnode\/*\/delete\nnode\/*\/revisions\nnode\/*\/revisions\/*\/revert\nnode\/*\/revisions\/*\/delete\nnode\/add\nnode\/add\/*\noverlay\/dismiss-message\nuser\/*\/shortcuts\nadmin\nadmin\/*\nbatch\ntaxonomy\/term\/*\/edit\nuser\/*\/cancel\nuser\/*\/edit\nuser\/*\/edit\/*\ndevel\/*\nnode\/*\/devel\nnode\/*\/devel\/*\ncomment\/*\/devel\ncomment\/*\/devel\/*\nuser\/*\/devel\nuser\/*\/devel\/*\ntaxonomy\/term\/*\/devel\ntaxonomy\/term\/*\/devel\/*",
"non_admin":"admin\/structure\/block\/demo\/*\nadmin\/reports\/status\/php"
},
"pathPrefixes":[
],
"ajaxCallback":"overlay-ajax"
},
"tableHeaderOffset":"Drupal.toolbar.height"
});
//--><!]]>
</script>
,並在瀏覽器控制檯,你可以看到下面的圖片Drupal.settings
對象適當的解釋。我的意思是,對象是根據json。在上述情況下沒有奇怪的物體。
問:是什麼原因造成這種奇怪的行爲?如何糾正它?
可能是由於ajax。檢查一下 - https://drupal.org/node/1683154 – George
好,那麼JSON必須在運行時更改。您可以嘗試設置[watch](https://developers.google.com/chrome-developer-tools/docs/tips-and-tricks#favorite-expression)。 – mb21