【问题标题】:jqGrid concatenating/building html tag incorrectlyjqGrid错误地连接/构建html标签
【发布时间】:2010-06-15 21:17:04
【问题描述】:

请原谅这篇文章的长度,但我需要解释我所看到的。 我有一个 onSelectRow 选项,它应该构建堆叠的 html <li> 标签(例如

<li>...</li>
  <li>...</li>
  <li>...</li>

) 最多我正在查看的静态 xml 元素的数量。但是我的脚本将所有图像 src 链接连接在一起,而不是构建整个 listobject 标记。我的 jqGrid 脚本中的所有其他内容都可以正常工作,但 xml 中的重复元素除外。

onSelectRow: function() {
    var gsr = $('#searchResults').jqGrid('getGridParam', 'selrow');
    if (gsr) {
     var data = $('#searchResults').jqGrid('getRowData', gsr);
    $('#thumbs ul').html('<li><a class='thumb' href='' + data.piclocation + '' title='' + data.pictitle + ''><img src='" + data.picthumb  + "' alt='" + data.pictitle + "' /></a><div class='caption'><div class='image-title'>" + data.pictitle + "</div></div></li>");
};"

我的 xml 文件是这样的:

<photo>
            <pic>
                <asset>weaponLib/stillMedia/slides/A106.jpg</asset>
                <thumb>weaponLib/stillMedia/thumbs/A106.jpg</thumb>
                <caption>Side view of DODIC A106</caption>
                <title>Side view of 22 caliber long rifle ball cartridge</title>
            </pic>
            <pic>
                <asset>weaponLib/stillMedia/slides/A106_A.jpg</asset>
                <thumb>weaponLib/stillMedia/thumbs/A106_A.jpg</thumb>
                <caption>Side view of DODIC A106</caption>
                <title>Side view of 22 caliber long rifle ball cartridge</title>
            </pic>
            <pic>
                <asset>weaponLib/stillMedia/slides/A106_B.jpg</asset>
                <thumb>weaponLib/stillMedia/thumbs/A106_B.jpg</thumb>
                <caption>Side view of DODIC A106</caption>
                <title>Side view of 22 caliber long rifle ball cartridge</title>
            </pic>
            <pic>
                <asset>weaponLib/stillMedia/slides/A106_C.jpg</asset>
                <thumb>weaponLib/stillMedia/thumbs/A106_C.jpg</thumb>
                <caption>Side view of DODIC A106</caption>
                <title>Side view of 22 caliber long rifle ball cartridge</title>
            </pic>
            <pic>
                <asset>weaponLib/stillMedia/slides/A106_D.jpg</asset>
                <thumb>weaponLib/stillMedia/thumbs/A106_D.jpg</thumb>
                <caption>Side view of DODIC A106</caption>
                <title>Side view of 22 caliber long rifle ball cartridge</title>
            </pic>

我的脚本在只看到一个序列时工作正常,但当它看到多个序列时,它将所有 html 放在标签内,然后标题和标题对它们也一样。它只生成一个&lt;li&gt;&lt;/li&gt; 标记集,而不是我想要的上面示例中的 5 个。

幻灯片(带缩略图)实用程序正在使用&lt;li&gt; 标签。

在 firebug 内部,我可以看到它为我构建的对象:

<a title="Side view of 22 caliber long rifle ball cartridgeSide view of 22 caliber long rifle ball cartridgeSide view of 22 caliber long rifle ball cartridgeSide view of 22 caliber long rifle ball cartridgeSide view of 22 caliber long rifle ball cartridge" href="weaponLib/stillMedia/slides/A106.jpgweaponLib/stillMedia/slides/A106_A.jpgweaponLib/stillMedia/slides/A106_B.jpgweaponLib/stillMedia/slides/A106_C.jpgweaponLib/stillMedia/slides/A106_D.jpg" class="thumb"><img alt="Side view of 22 caliber long rifle ball cartridgeSide view of 22 caliber long rifle ball cartridgeSide view of 22 caliber long rifle ball cartridgeSide view of 22 caliber long rifle ball cartridgeSide view of 22 caliber long rifle ball cartridge" src="weaponLib/stillMedia/thumbs/A106.jpgweaponLib/stillMedia/thumbs/A106_A.jpgweaponLib/stillMedia/thumbs/A106_B.jpgweaponLib/stillMedia/thumbs/A106_C.jpgweaponLib/stillMedia/thumbs/A106_D.jpg"></a>

在 jqGrid 中,单元格持有:

<td title="weaponLib/stillMedia/slides/A106.jpgweaponLib/stillMedia/slides/A106_A.jpgweaponLib/stillMedia/slides/A106_B.jpgweaponLib/stillMedia/slides/A106_C.jpgweaponLib/stillMedia/slides/A106_D.jpg" style="text-align: center; display: none;" role="gridcell">weaponLib/stillMedia/slides/A106.jpgweaponLib/stillMedia/slides/A106_A.jpgweaponLib/stillMedia/slides/A106_B.jpgweaponLib/stillMedia/slides/A106_C.jpgweaponLib/stillMedia/slides/A106_D.jpg</td>

我知道 jqGrid 构建它是错误的。对于修复它的方向,我感到很困惑。任何建议将不胜感激。

【问题讨论】:

  • 此应用程序的在线示例可以在 www.serco-hrc.com/testMe/index.html 浏览,只有小型武器菜单连接到网格和数据。 A106 是要显示多张图片的行之一。

标签: html jqgrid selection html-lists


【解决方案1】:

在我看来,声明者

$('#thumbs ul').html('<li><a class='thumb' href='' + data.piclocation + '' title='' data.pictitle + ''><img src='" + data.picthumb  + "' alt='" + data.pictitle + "' /></a><div class='caption'><div class='image-title'>" + data.pictitle + "</div></div></li>");

onSelectRow 的内部应该稍作改动以使用更多 " 而不是 '(或者您应该使用双 '):

$('#thumbs ul').html("<li><a class='thumb' href='" +
                      data.piclocation + "' title='" + data.pictitle +
                      "'><img src='" + data.picthumb  +
                      "' alt='" + data.pictitle +
                  "' /></a><div class='caption'><div class='image-title'>" +
                   data.pictitle + "</div></div></li>");

您可以在 stackoverflow.com 上的颜色中看到,现在一切看起来都更正确了。

【讨论】:

  • 奥列格,很抱歉造成混乱。当我发布我的问题时,我不知道如何在我的问题中定义脚本。我已经开始修改我的脚本以供查看。然后我找到了嵌入脚本的正确方法。我的原始脚本看起来像你的建议。当网站只需要显示 1 张图片时,该应用程序可以正常工作。但是当需要生成堆叠的
  • 时,它就变得混乱了。我在serco-hrc.com/testMe/index.html 有一个版本。这应该让您看到发生了什么,而无需我在此站点上放置快照。 A085(单图)A106(多图)下
  • 轻武器菜单项。任何建议/方向将不胜感激。托尼
  • 对不起,我不太明白你的代码应该做什么。我可以找到&lt;DIV id=thumbs class=navigation&gt;&lt;UL class="thumbs noscript"&gt;&lt;LI&gt;&lt;A class=thumb title="Side view of 22 caliber short blank cartridge" href="weaponLib/stillMedia/slides/A085.jpg"&gt;&lt;IMG alt="Side view of 22 caliber short blank cartridge" src="weaponLib/stillMedia/thumbs/A085.jpg"&gt;&lt;/A&gt;&lt;DIV class=caption&gt;&lt;DIV class=image-title&gt;Side view of 22 caliber short blank cartridge&lt;/DIV&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/DIV&gt;,我不明白但它看起来是正确的。创建 jqGrid 的主要代码和一些我找不到的 HTML。
  • 猜你喜欢
    相关资源
    最近更新 更多
    热门标签