简体   繁体   English

derbyjs 从 x-bind 在服务器上运行代码

[英]derbyjs running code on server from x-bind

I'm trying to run some server only code from an event on the client in derby.js I'm using x-bind to bind the event on the view like so:我正在尝试从 derby.js 客户端上的事件运行一些仅服务器代码我正在使用 x-bind 将事件绑定到视图上,如下所示:

<a href="#" x-bind="click: func">click me</a>

and on the app:并在应用程序上:

exports.func=function(e,el,next){
    // i want to run some server code here, but it runs on the client only
}

So:所以:

  1. Can this be done in any way?这可以以任何方式完成吗?
  2. if not, is there any way to use sockets in a 'native' way on derby.js如果没有,有没有办法在 derby.js 上以“本机”方式使用套接字

I simply don't want to fall back to ajax with server routes when all the rest is real time.当所有其余的都是实时的时,我只是不想回到带有服务器路由的 ajax。

You can route the request onto the server via the model ( model.fetch() & model.subscribe() ).您可以通过模型( model.fetch() & model.subscribe() )将请求路由到服务器上。 If it's just retrieving some data from the server, you are basically all set.如果它只是从服务器检索一些数据,那么您基本上都准备好了。 Keep a reference to the model for when you need it (in app.ready callback as pointed out by switz).在需要时保留对模型的引用(在 switz 指出的 app.ready 回调中)。

To use sockets directly or to extend the model (which uses sockets in the background) see https://groups.google.com/forum/?pli=1#!topic/derbyjs/60gouek7334要直接使用套接字或扩展模型(在后台使用套接字),请参阅https://groups.google.com/forum/?pli=1#!topic/derbyjs/60gouek7334

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM