JSON data with property name "length" causes a bug

JSON data with property name "length" causes a bug

nivniv Posts: 3Questions: 0Answers: 0
edited August 2011 in General
Hi,
this is my data

var ds_playlist = [
{
"stime": "2011-08-23T12:40:02",
"status": 0,
"channel": "RADIO ZU",
"artist": "DAN BALAN",
"title": "FREEDOM (RADIO-VIDEO EDIT)",
"track": "DAN BALAN - FREEDOM (RADIO-VIDEO EDIT)",
"position": 45,
"duration": 196,
"length": 215
},
{
"stime": "2011-08-23T12:35:32",
"status": 0,
"channel": "KISS FM",
"artist": "DAN BALAN",
"title": "FREEDOM (RADIO MIX)",
"track": "DAN BALAN - FREEDOM (RADIO MIX)",
"position": 5,
"duration": 182,
"length": 212
},..

running the table generates an error of Uncaught TypeError: Object # has no method 'slice'

it took me hours to debug and found that when i remove the property "length" everything is ok

can u please instruct what should i do since the property "length" cannot be changed on my side

here is my datatable init


$(document).ready(function () {

$('.btnEdit').button({icons: {primary: "ui-icon-pencil"}, text: true});

$('#nttgrid').dataTable({
"bJQueryUI": true,
"bAutoWidth": false,
"sPaginationType": "full_numbers",
"sDom": 'T<"clear"><"H"lfr>t<"F"ip>',
"aaData": kuku_data,
"aoColumns": [
{ "mDataProp": "stime", "sTitle": "<%= Resources.Resource.StartTime %>" },
{ "mDataProp": "status", "sTitle": "<%= Resources.Resource.TypeOfBroadcast %>" },
{ "mDataProp": "channel", "sTitle": "<%= Resources.Resource.Channel %>" },
{ "mDataProp": "artist", "sTitle": "<%= Resources.Resource.Artist %>" },
{ "mDataProp": "title", "sTitle": "<%= Resources.Resource.SongTitle %>" },
{ "mDataProp": "track", "sTitle": "<%= Resources.Resource.Track %>" },
{ "mDataProp": "position", "sTitle": "<%= Resources.Resource.Position %>", "sClass": "center" },
{ "mDataProp": "duration", "sTitle": "<%= Resources.Resource.Duration %>", "sClass": "center" }
]

});


});

TIA

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    in order to use slice and length, you need to use an array. your objects don't have those properties or functions.
  • MrBaseball34MrBaseball34 Posts: 96Questions: 0Answers: 0
    While length is not a reserved word in javascript, you really should avoid naming functions and variables with the same name as javascript gobal functions.
    Please return the data as len
  • MrBaseball34MrBaseball34 Posts: 96Questions: 0Answers: 0
    [quote]the property "length" cannot be changed on my side[/quote]
    And why can it not be changed?
  • allanallan Posts: 63,530Questions: 1Answers: 10,473 Site admin
    This is the line of code in DataTables which is tripping this up:

    [code]
    var aDataIn = (typeof aDataSupplied.length == 'number') ?
    [/code]

    I've just committed a fix for this which you can pick up from the DataTables download page as the 1.8.2.dev nightly: http://datatables.net/download . The fix is to use the jQuery method $.isArray which is designed for exactly this sort of thing!

    Regards,
    Allan
  • nivniv Posts: 3Questions: 0Answers: 0
    10x very much
This discussion has been closed.