Dynatable callback function not working

僤鯓⒐⒋嵵緔 提交于 2019-12-12 04:12:20

问题


I'm trying to bind click event to dynatable generated, I've tried $('#my-final-table hr').on("click",function(){alert("foo");}); so I'm trying to bind it after loading data:

var jsondata=[
  {
    "band": "Weezer",
    "song": "El Scorcho"
  },
  {
    "band": "Chevelle",
    "song": "Family System"
  }
];
$('#my-final-table').dynatable({
  dataset: {
    records: jsondata
  }
})
.bind('dynatable:afterProcess', function(){alert('foo')});

But it doesn't work, no alert is shown after loading. JSFiddle:http://jsfiddle.net/maysamsh/pDVvx/


回答1:


In the example from the dynatable website they manually call the afterProcess function the first time it runs. For your code that looks something like:

var processingComplete = function(){alert('foo')};
$('#my-final-table').dynatable({
  dataset: {
    records: jsondata
  }
}).bind('dynatable:afterProcess', processingComplete);

// call the first time manually
processingComplete();

If you want to see this in a fiddle, check here: http://jsfiddle.net/pDVvx/2/

In case you were interested the dynatable code I'm referring to is:

$table.dynatable({
  // settings & code here
}).bind('dynatable:afterProcess', updateChart);

// Run our updateChart function for the first time.
updateChart();

Best of luck!




回答2:


try adding a parameter to your callback function

$('#my-final-table').dynatable({
   dataset: {
   records: jsondata
}
}).bind('dynatable:afterUpdate', processingComplete);

function processingComplete(a)
{
 alert('foo');
}


来源:https://stackoverflow.com/questions/23200892/dynatable-callback-function-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!