可动态回调函数不起作用 [英] Dynatable callback function not working

查看:267
本文介绍了可动态回调函数不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将点击事件绑定到生成的dynatable,我已经尝试过$('#my-final-table hr').on("click",function(){alert("foo");});,所以我试图在加载数据后将其绑定:

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

但是它不起作用,加载后不会显示任何警报. JSFiddle: http://jsfiddle.net/maysamsh/pDVvx/

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

推荐答案

在可动态创建的网站的示例中,他们在第一次运行afterProcess函数时手动对其进行了调用.对于您的代码,如下所示:

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();

如果您想在小提琴中看到它,请在此处查看: http://jsfiddle.net/pDVvx/2/

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();

祝你好运!

这篇关于可动态回调函数不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆