2015-03-13 71 views
0

我想做一个非常简单的html tableTree。我没有任何有关html/javascript编程的经验,所以我遍历谷歌找到我试图实现的例子。Uncaught TypeError jqute

我目前正在试图找到一个简单的方法来传递一个json文件到一个html文档中,并且我通过执行代码部分我自己并使用ajax和jquery已经取得了成功。

但是我发现了一个使用jqote2的例子,虽然实现这个例子给了我一个错误“Uncaught TypeError:undefined不是一个函数”。我想我失去了一些东西,虽然我想不出什么,所以我希望我能得到一些在这里:)援助

<!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')); 

所以我失去了什么:)我已经检查并包含文件确实存在和路径是正确的。

回答

0

您在CData部分有问题 像“<”和“&”这样的字符在XML元素中是非法的。

“<”将产生错误,因为解析器将其解释为新元素的开始。

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

某些文本(如JavaScript代码)包含大量“<”或“&”字符。为了避免错误,脚本代码可以定义为CDATA。

解析器忽略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> 

第一循环将削减对象为数组,你可以不写字符串,第二个一个会让你得到的键和值,然后做你想要的东西^ _ ^希望这可以帮助

+0

我们在这里谈论什么解析器因为我明白它

相关问题