我在this旁边使用Brython库作为哈希路由器。我最初用纯JavaScript编写代码。路线的定义如下:
Router.add({
path: '#/action/login',
on: function() {
/* I don't know how to port this call */
populate_from_query(this.query);
/* These calls can be ported: */
Materialize.updateTextFields();
do_login($('#email').val(), $('#password').val());
}
});
在Brython,到目前为止,我有:
def route_on_action_login():
# I can't write this as Python because I can't access the, "this object"
#populate_from_query(this.query)
window.Materialize.updateTextFields()
do_login(document['email'].value, document['password'].value)
window.Router.add({
'path': '#/action/login',
'on': route_on_action_login
})
如何从作为Javascript回调传入的Brython函数中访问函数的“this”参数?