【问题标题】:Uncaught TypeError jqute未捕获的 TypeError jqute
【发布时间】:2015-03-13 08:41:55
【问题描述】:

我正在尝试制作一个非常简单的 html tableTree。我没有关于 html/javascript 编程的经验,所以我正在遍历谷歌来查找我想要实现的示例。

我目前正在尝试找到一种简单的方法将 json 文件传递​​到 html 文档中,并且我已经成功地通过自己执行该代码部分并使用 ajax 和 jquery。

但是我找到了一个使用 jqote2 的示例,尽管实现此示例给我一个错误“未捕获的类型错误:未定义不是函数”。我想我错过了一些东西,虽然我不知道是什么,所以我希望我能在这里得到一些帮助:)

<!DOCTYPE html>
<html>
<head>
  <script src="jquery/jquery-1.11.2.min.js"></script>
  <script src="jqote2/jquery.jqote2.js"></script>
  <script type="text/html" id="template">
  <![CDATA[
    <tr>
      <td class="no"><%= j+1 %></td>
      <td class="title"><%= this.Title %></td>
    </tr>
  ]]>
  </script> 
  <!-- 2 load the theme CSS file -->
  <title>Test</title>
  </head>

  <body>
  <script type="text/javascript">
    var jsondata = [{"Title": "Dr.", "Surname": "House", "Firstname":  "Geronimo"},{"Title": "Mr.", "Surname": "Franklin", "Firstname": "Benjamin"}];
    // Now call jQote on the template providing your json data
    $('#template').jqote(jsondata).appendTo($('#users'));
  </script>

  <div>
    <table id="users"></table>
  </div>

</body>
</html>

我根据http://aefxx.com/jquery-plugin/jqote/ 中的示例构建了这段代码

运行此代码时出现错误

$('#template').jqote(jsondata).appendTo($('#users'));

那么我错过了什么 :) 我已经检查过,包含的文件确实存在并且路径是正确的。

【问题讨论】:

    标签: javascript jquery html treetable jqote


    【解决方案1】:

    CData 部分有问题 像“

    "

    "&" 将产生错误,因为解析器将其解释为字符实体的开始。

    有些文本,比如 JavaScript 代码,包含很多“

    解析器会忽略 CDATA 部分中的所有内容。 moveover 你不能像以前那样写字符串

    http://www.w3schools.com/xml/xml_cdata.asp

    从 json 对象中绘制表格会是这样的

    <!DOCTYPE html>
    <html>
    <head>
      <script src="jquery-1.11.2.min.js"></script>
    
      <!-- 2 load the theme CSS file -->
      <title>Test</title>
      </head>
    
    
      <script type="text/javascript">
        var jsondata = [{"Title": "Dr.", "Surname": "House", "Firstname":  "Geronimo"},{"Title": "Mr.", "Surname": "Franklin", "Firstname": "Benjamin"}];
        // Now call jQote on the template providing your json data
    
        $( document ).ready(function() {
           $.each( jsondata, function( key, value ) {
                $.each( value, function( k, v ) {
                        $("#"+k).html(v);
    
                });
        });
    });
    
      </script>
    
       <body>
      <table>
      <tr>
      <td id="Title"></td>
      <td id="Surname"></td>
      <td id="House"></td>
      <td id="Firstname"></td>
      </tr>
      </table>
    
    </body>
    </html>
    

    第一个循环将把对象分解成数组,第二个循环让你得到键和值,然后用它们做你想做的事情^_^希望对你有帮助

    【讨论】:

    • 我们在这里讨论的是什么解析器,因为据我所知
    • 好吧,也许你正在努力做一些事情可以很容易地完成而不涉及 CDATA 标签..你能解释一下你的目标是什么:)
    • 好的,我知道了,你想使用来自 json 的数据来绘制 HTML 表格吗?并在其对应的单元格中分配每个值?
    • 我想使用 jQuery treetable 来表示我的数据。我有一个在运行时创建 json 文件的程序,我希望这个文件被动态引入到树表中。
    • 我的目标也是让我的代码尽可能简单。没什么花哨的
    猜你喜欢
    • 1970-01-01
    • 2014-08-07
    • 2014-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多