最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - JQuery DataTable fnUpdate not updating values from object source: Uncaught TypeError: Cannot call method 'f

programmeradmin2浏览0评论
$(document).ready(function() {
     var oTable = $('#example').dataTable({
       "aoColumns": [
        {"mData": "name"}
       ]
     });
     // Sample model
     var Person = function() {
       this.name = null;
     };
     p = new Person(); 

     // Add first row.
     oTable.fnAddData(p); 

     // Try first update.
     oTable.fnUpdate( {name: 'hardcoded'}, 0 ); // <--- Works

     // Change the name property.
     p.name = 'updated';
     oTable.fnUpdate( p, 0 ); // <--- Doesn't work
   } );

I can't get this to work, when i run the oTable.fnUpdate( p, 0 ); i am getting

Uncaught TypeError: Cannot call method 'fnSetData' of undefined

Why?

$(document).ready(function() {
     var oTable = $('#example').dataTable({
       "aoColumns": [
        {"mData": "name"}
       ]
     });
     // Sample model
     var Person = function() {
       this.name = null;
     };
     p = new Person(); 

     // Add first row.
     oTable.fnAddData(p); 

     // Try first update.
     oTable.fnUpdate( {name: 'hardcoded'}, 0 ); // <--- Works

     // Change the name property.
     p.name = 'updated';
     oTable.fnUpdate( p, 0 ); // <--- Doesn't work
   } );

I can't get this to work, when i run the oTable.fnUpdate( p, 0 ); i am getting

Uncaught TypeError: Cannot call method 'fnSetData' of undefined

Why?

Share Improve this question asked Oct 19, 2013 at 13:29 brazorfbrazorf 1,9612 gold badges32 silver badges55 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

Use a proper object to initialize persons. Then you can use later fnUpdate with an object call like you did

 var p = {
     name: null
 };

See here for full code: jsfiddle

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论