0

I'm trying to use the 'd3.dispatch' feature in one of my project. I want to setup a custom event and dispatch it to the available listenres using namespace.

I did this :

var dispatcher = d3.dispatch("period_selected");

brush.on("brush", function() {
  var s =  brush.extent()

  // patch the event to listeners
  dispatcher.period_selected(s);

});

// register listener for the event namespaced 
dispatcher.on("period_selected.my_namespace", function(s,f) {

    console.log(event.period_selected);
});

But I can't get back the with namespace as result. Do you have any idea?

Thanks in advance

4

1 に答える 1

1

名前空間は引数として渡されず、イベントにも割り当てられません。名前空間が本当に必要な場合は、それをパラメーターとして渡す必要があります。

dispatch.period_selected(s, "my_namespace")

...ここで利用可能になります:

dispatcher.on("period_selected.namespace", function(s, namespace) {
    // Use namespace here
});
于 2013-11-21T21:31:45.373 に答える