开发者

How give parameters to ExtJS controller from Ext.application

Actually I'm creating my first ExtJS 4 MVC application. Following the application guide from documentation, I initialize my controller like that :

Ext.application({
name: 'RateManagement',

appFolder: 'softcom',

context: null,

constructor: function(context) {
    this.context = context;
},

launch: function() {
    Ext.create('Ext.Panel', {
        layout: 'fit',
        renderTo: 'rate-management',
        items: [
            {
                xtype : 'ratelist'
            },
            {
 开发者_StackOverflow中文版               xtype : 'rateedit'
            }
        ]
    });
},

controllers: [
              'Rate'
          ],

});

But for future ajax call, my controller need to know the ajaxUrl which is coming from Liferay 6. In Liferay, I can get URL like that :

<portlet:resourceURL var="listRates" escapeXml="false" id="listRates"></portlet:resourceURL>
<script type="text/javascript">
    var rateContext = {
        contextPath: '<%=request.getContextPath()%>',
        listRatesUrl : '${listRates}',
        strings: strings
    };
</script>

My idea is to pass the var rateContext to my controller "Rate".

Any Idea? Thank you!!


Concept of passing variable from app to controller looks wrong to me. Instead I would create getter somewhere in your app config

Ext.application({
  // ...

  context: null,
  getContext: function() {
    return this.context;
  },
  constructor: function(context) {
    this.context = context;
  },

  // ...
});

And then you can get it from controller using:

this.application.getContext()

But if you would like to use approach of passing variable to controller you always can use yourApp.getController("Rate") (you can do it in your lounch method) in order to access the controller.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜