0

Question on Model/Controller/Refresh in mojito

Hi,
I have a question around the relationship between Model and Controller
and the refresh mechanism:

I have a mojit, and what it is trying to do is to retrieve the data
from the model every 5 seconds, and refresh the html (a box area in
page) with the new data.
Code sample as below, note that my model.server.js must run on the
server because it is using a server singleton object.

binders/index.js:

       bind: function(node) {
           this.node = node;
           var mp = this.mojitProxy;
           setTimeout(function() {
               mp.refreshView();
               },5000);
       },
       onRefreshView: function(node, element) {
         this.bind(node, element);
       }

controller.common.js:
                       index: function(ac) {
                               var type = ac.config.get('type');

                               ac.models.AxisModel.getData(type, function(err, data) {
                                       if (err) {
                                               ac.error(err);
                                               return;
                                       }
                                       ac.done(data);
                               });
                       }

model.server.js: (AxisModel)
                       getData: function(type, callback) {

                               var c = Y.NCClient.getInstance(); // a singleton object sitting in
the server
                               var result = {};
                               result.items = c.getData('test');
                               result.title = type;

                               callback(null, result);
                       }

index.mu.html:
<div id="{{mojit_view_id}}" class="mojit">
<table>
<caption>{{title}}</caption>
 {{#items}}
   <tr><td class="axis">{{axis}}</td><td class="position">{{pos}}</td></tr>
 {{/items}}
</table>
</div>

However I am encountering this problem:
If the controller affinity is server, then the page runs okay, and the
server is returning the rendered html every 5 seconds.
If the controller affinity is client, then the page will not refresh
(although initially rendered successfully), an error will occur saying
ac.models.AxisModel is not defined.
Is it correct to say that if model must run on the server (because of
dependency on server) then the controller must also run on the server
for the refresh to work?
If so is there any way to workaround this so I can have controller to
run on the client if I choose to?

by
1 Reply
  • The problem is that your controller is sitting on the client but calling a model that only exist on the server.

    You will need to define a client version of AxisModel for this to work...
    0

Recent Posts

in Yahoo! Mojito