开发者

Sencha: Using Ext.Router outside of MVC structure

I'm 开发者_如何转开发working on a Sencha Touch app, which currently isn't using controllers. I would like to use Ext.Router to take the visitor to a particular card in a panel. I've seen suggestions that it is possible to use the Ext.Router without using a strict MVC setup. But the example in the API looks like this (see: http://dev.sencha.com/deploy/touch/docs/?class=Ext.Router):

map.connect('dashboard', {controller: 'home', action: 'index'});

Is there a way to, for instance, put a function into map.connect that would show a particular card in a panel?

Second question: is it even worth trying to wrestle with this, or would it be easier to update the app with controllers? (It's a pretty small app in the early stages of development, and would probably have 3 controllers if we went that route.)


I had this same question and was hell bent on not using a controller because I had no time to restructure the code I was given. Like the chosen post reluctantly suggested I used the Ext.History class. If you call this in your onReady function it will activate the myPanel panel with the URL: www.mypage.com/#my-url-slug

function initialiseHistory() {
  Ext.History.init();
  urlToken = Ext.History.getToken();
  if(urlToken == 'my-url-slug') {
      Ext.getCmp('tabpanel').setActiveItem('myPanel', false);
  }
}

Dirty I know.. but did the job.


The Router is kinda married to the controller and doesn't really provide a way to do what you're asking. If what you're trying to do is show a card based on the URL hash then ya go with a controller cause its trivial to implement.. if you're hell bent on not using a controller for some reason the only thing that comes to mind is Ext.History fires a 'change' event when the url hash changes, you could listen for that event and take appropriate action I suppose.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜