BUI

其它版本:

API for BUI 1.4.8

Show:

bui.emitter Class

事件发射器

方法说明:

on: 监听事件
off: 取消事件监听
trigger: 触发自定义事件
one: 监听一次事件

Constructor

bui.emitter

()

Example:

js:

     // 初始化
     var emitter = bui.emitter();

     // 自定义search事件监听
     emitter.on("search",function(val){
       search(val);
     });

     $("#id").click(function (e) {
       var val = $("input").val();
       emitter.trigger("search",val);
     })

     // 搜索
     function search(val) {
       bui.ajax({
         url: "",
         data: {
           keyword: val
         }
       }).then(function () {
         // 拿到数据返回渲染
       })
     }

Item Index

Methods

Methods

off

(
  • [type]
  • [callback]
)

取消事件

Parameters:

  • [type] String optional

    [ 自定义事件名称 ]

  • [callback] Function optional

    [ 触发的回调 ]

Example:

  // 取消所有search事件
  emitter.off("search");

on

(
  • [type]
  • [callback]
)

监听自定义事件

Parameters:

  • [type] String optional

    [ 自定义事件名称 ]

  • [callback] Function optional

    [ 触发的回调 ]

Example:

  // 自定义search事件监听
  emitter.on("search",function(val){
    search(val);
  });

one

(
  • [type]
  • [callback]
)

只监听在第一次的时候触发

Parameters:

  • [type] String optional

    [ 自定义事件名称 ]

  • [callback] Function optional

    [ 触发的回调 ]

Example:

  // 监听一次
  emitter.one("search",function(val){
    search(val);
  });

trigger

(
  • [type]
  • [arguments]
)

触发事件

Parameters:

  • [type] String optional

    [ 自定义事件名称 ]

  • [arguments] String | Object | Number optional

    [ 需要传给自定义事件的参数,可以有多个 ]

Example:

  $("#id").click(function (e) {
    emitter.trigger("search",e);
  })