EEUI.APP
首页
文档
- 指南
- 组件
- 模块
插件
- 插件市场
- 开发文档
热更新
控制台
Editor
例子
社区
### # Android
[WXSDKEngine registerService:@"SERVICE_NAME" withScript: @"SERVICE_JS_CODE" withOptions: @{}];// or[WXSDKEngine registerService:@"SERVICE_NAME" serviceScriptUrl: @"SERVICE_JS_URL" withOptions: @{}];
HashMap<String, String> options = new HashMap<>()options.put("k1", "v1")String SERVICE_NAME = "SERVICE_NAME"String SERVICE_JS_CODE = "SERVICE_JS_CODE"boolean result = WXSDKEngine.registerService(SERVICE_NAME, SERVICE_JS_CODE, options)
### # Webparams of
optionsCould have { create, refresh, destroy } lifecycle methods. In create method it should return an object of what variables or classes would be injected into theWeexinstance.
## # 样例
<script src="SERVICE_JS_CODE_URL"></script>
Use JSService
service.register(SERVICE_NAME / same string with native /, {/JSService lifecycle. JSServicecreatewill before then each instance lifecyclecreate. The return paraminstanceis Weex protected param. This object will return to instance global. Other params will in theservicesat instance.@param {String} id instance id@param {Object} env device environment@return {Object}/create: function(id, env, config) {return {instance: {InstanceService: function(weex) {var modal = app.requireModule('modal')return {toast: function(title) {modal.toast({ message: title })}}}},NormalService: function(weex) {var modal = app.requireModule('modal')return {toast: function(title) {modal.toast({ message: title })}}}}},/JSService lifecycle. JSServicerefreshwill before then each instance lifecyclerefresh. If you want to reset variable or something on instance refresh.@param {String} id instance id@param {Object} env device environment/refresh: function(id, env, config){},/**JSService lifecycle. JSServicedestroywill before then each instance lifecycledestroy. You can deleted variable here. If you doesn't detete variable define in JSService. The variable will always in the js runtime. It's would be memory leak risk.@param {String} id instance id@param {Object} env device environment@return {Object}*/destroy: function(id, env) {}})
在 GitHub 上编辑此页
<script>var _InstanceService = new InstanceService(weex)var _NormalService = new service.NormalService(weex)module.exports = {created: fucntion() {// called modal module to toast something_InstanceService.toast('Instance JSService')_NormalService.toast('Normal JSService')}}</script>
最后一次更新: 6/7/2019, 8:03:58 AM
