开发者

Jquery Template data (Decimal datatype) adds Zero at end - Why?

Can anyone tell me why my "Id" always gets a zero added at the end? and how to fix that?

http://jsfiddle.net/55u9M/13/

<script id="myTemplate" type="text/x-jquery-tmpl">
    <tr开发者_如何学C id='${Id}'>${Id}</tr>
</script>

<div id="tblMyTable"></div>


$(document).ready(function(){

 var test = [
  { Id: 43000796568231936 , ReleaseYear: "1998" },
  { Id: 43000796568231937 , ReleaseYear: "1999" },
  { Id: 43000796568231938 , ReleaseYear: "1976" }
  ];

    $("#myTemplate").tmpl(test).appendTo("#tblMyTable");

});


Looks like a JS WTF...

alert(parseInt(43000796568231936));

It's changing your numbers to 43000796568231940.

This happens in Google Chrome, Firefox, and IE.

You can fix this by changing your integers to strings: http://jsfiddle.net/55u9M/16/

Change your JSON from:

var test = [
    { Id: 43000796568231936, ReleaseYear: "1998" },
    { Id: 43000796568231937, ReleaseYear: "1999" },
    { Id: 43000796568231938, ReleaseYear: "1976" }
];

To

var test = [
    { Id: '43000796568231936', ReleaseYear: "1998" },
    { Id: '43000796568231937', ReleaseYear: "1999" },
    { Id: '43000796568231938', ReleaseYear: "1976" }
];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜