Skip to content

请问怎么使用回调函数 #3

@dwdcth

Description

@dwdcth

这段代码里面的 set_data.call0(&data)
set_data 是什么啊

let handler = move |res:&JsValue| -> Result<JsValue, JsValue> {
        let confirm:bool = Reflect::get(res, &JsValue::from("confirm"))?.as_bool().unwrap_or(false);
        let cancel:bool = Reflect::get(res, &JsValue::from("cancel"))?.as_bool().unwrap_or(false);
        let data = Object::new();
        if confirm{
            Reflect::set(&data, &JsValue::from("data"), &JsValue::from("用户点击确定"))?;
        } else if cancel {
            Reflect::set(&data, &JsValue::from("data"), &JsValue::from("用户点击取消"))?;
        }
        set_data.call0(&data)
    };
    let handler = Closure::wrap(Box::new(handler) as Box<dyn Fn(&JsValue) -> Result<JsValue, JsValue> >);
    Reflect::set(&param, &JsValue::from("success"), handler.as_ref())?;
    handler.forget();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions