2016-12-13 64 views
0

我有一个xe:jsonRpcService,我想传递给一个csjs类。这怎么可能?将xe:jsonRpcService传递给csjs类

服务:

<xe:jsonRpcService id="jsonRpcService1" serviceName="rpcServices"> 
    <xe:this.methods> 

     <xe:remoteMethod name="loadEntity" 
      script="PersonBean.loadEntity(id);"> 
      <xe:this.arguments> 
       <xe:remoteMethodArg name="id" type="string"></xe:remoteMethodArg> 
      </xe:this.arguments> 
     </xe:remoteMethod> 

    </xe:this.methods> 
</xe:jsonRpcService> 

呼叫我的课在输出脚本:

formHelper = new FormHeler(rpcServices) ; 

的csjs类:

function Formhelper(service) { 
    //... 
    this.loadEntity = function(id) { 
     //... 
     resultObj = service.loadEntity(id) ; 
     //... 
    } 
} 

在类作品使用rpcServices.loadEntity。但我想将它作为参数传递,所以我可以使用具有不同服务的类。

rpcServices作为类构造函数的参数不起作用。是否有另一种方法将引用传递给服务并使其在课程中可用?

回答

0

rpcServices是REST服务端点的服务器端集合(this.methods)。您无法将该集合传递给CSJS,您只能通过的一个端点的结果。

认为它就像试图将SSJS脚本库传递到CSJS函数一样。

0

谢谢保罗。通过将服务名称传递给课程来实现它。然后我使用eval来调用rpc方法:

var serviceName = "rpcServices" ; 
formHelper = new FormHelper(serviceName) ; 

function FormHelper(serviceName) { 
    this.serviceName = serviceName ; 

    //... 
    this.loadEntity = function(id) { 
     var rpcResultObj = eval(this.serviceName + ".loadEntity(\"" + id + "\")") ; 
    } 
    //... 
} 

现在我可以使用我的FormHelper方法与不同的服务。