Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【PR】请教下iOS 端 native怎么传值到js #1270

Closed
voidxin opened this issue Sep 21, 2016 · 6 comments
Closed

【PR】请教下iOS 端 native怎么传值到js #1270

voidxin opened this issue Sep 21, 2016 · 6 comments

Comments

@voidxin
Copy link

voidxin commented Sep 21, 2016

iOS native本地需要传参数到js页面,请教下怎么操作。

@acton393
Copy link
Contributor

acton393 commented Sep 21, 2016

@voidxin 可以自定义module ,在callBack里面 返回到js
可以参考 doc 扩展

@voidxin
Copy link
Author

voidxin commented Sep 21, 2016

@acton393 ok,谢了

@voidxin voidxin closed this as completed Sep 21, 2016
@voidxin
Copy link
Author

voidxin commented Sep 22, 2016

@acton393 请问这里回调之后的function只能执行或调用native的方法吗?(iOS端)

  var eventModule = require('@weex-module/event'); 
  eventModule.openURL('url',function(ret) {   
     //这里只能执行native的方法吗?
      nativeLog(ret);
  });

我在js中使用本js中的方法时它不执行(如下):

var eventModule = require('@weex-module/event'); 
  eventModule.openURL('url',function(ret) {   
     //这是本js中的一个方法,不执行test()方法
      this.test();
    //当我换成native的一个方法时,如下的updateVersionWithStr(),能调用执行
       eventModule.updateVersionWithStr(result);
  });

//js中的test方法

test: function() {
        //TODO SOMETHING
},

请问回调之后的function只能执行或调用native的方法吗? 我该怎么做?

@voidxin voidxin reopened this Sep 22, 2016
@voidxin
Copy link
Author

voidxin commented Sep 22, 2016

ok,我发现问题了,作用域的问题,要在外部先申明var self = this;

var self = this
eventModule.openURL(''url", function(ret){
    self.test()
})

这样就可以了。

@voidxin voidxin closed this as completed Sep 22, 2016
@acton393
Copy link
Contributor

@voidxin http://openmymind.net/2012/2/3/Node-Require-and-Exports/ 可以参考下这里看下

@Binglin
Copy link

Binglin commented Jan 20, 2017

原生界面直接跳转weex界面,同时需要传递参数过去,有什么方法吗?
这里的解决方案 仅适用于 在weex界面调用原生模块,原生再返回给weex数据

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants