【问题标题】:Reading parameters enterd on the screen读取屏幕上输入的参数
【发布时间】:2010-10-18 11:29:20
【问题描述】:

我有一个接受用户参数的页面。我在我的操作中使用 params.playerId 读取了这个参数。然后用它进行计算。

我现在更改了我的 UI,并使用 extJS 进行显示。 因此,我有一个 edit 和一个 editData 操作。 editData 操作具有运行 sql 并执行相应 js 文件并显示 edit.jsp 的代码。但是,在 editData 操作中,当我使用 params.playerId 时,我得到一个空值。

对于这种情况,可以采取哪些工作方式?

我在与 extJS 集成之前的代码:调用 list 动作并显示 list.gsp 和数据。

定义列表 = {

def session = sessionFactory.getCurrentSession() def result = session.createSQLQuery("select player_id from w.music where player_id=(params.playerId)").list();
def tuneInstanceList = new ArrayList()
def tune = new Tune()
结果.each
{ tune.playerId = 它
tune.playerPrice = "100" tuneInstanceList.add(tune)
} [recoveryInstanceList:recoveryInstanceList]
}
现在,当我与 extJS 集成时,我将 params.playerId 的值设为 null。代码如下。

list.gsp:

   <script type="text/javascript">  

   var ds = new Ext.data.Store({ 
       autoLoad: true, 
       proxy: new Ext.data.HttpProxy({ 
       url: 'http://localhost:8080/tune/music/listData'}), 
       reader: new Ext.data.JsonReader({ 
        results: 'total', 
        root:'items', 
        id:'id' 
       }, 
       [ 
               {name: 'playerId'}, 
               {name: 'playerPrice'} 

          ] 
       ) 
    }); 

    var cm = new Ext.grid.ColumnModel([ 
        {header: "Player Id", width: 70, sortable:true,  dataIndex: 'playerId'}, 
        {header: "Player Price", width: 90, dataIndex: 'playerPrice'} 


    ]); 
    //cm.defaultSortable = true; 

    // create the grid 
    var grid = new Ext.grid.GridPanel({ 
        ds: ds, 
        cm: cm, 
        renderTo:'grid-example', 
        width:1300, 
        height:300 
    }); 
            </script> 

<div class="body"> 
<!--<g:javascript library="examples"/>--> 
<!-- EXAMPLES --> 
<h1>Ext Grid</h1> 



 <div id="grid-example"></div> 


</div> 

我的控制器操作:

def list={ }

def listData = {
 def session = sessionFactory.getCurrentSession()   
def result = session.createSQLQuery("select player_id from w.music where player_id=    (params.playerId)").list();   
def tuneInstanceList = new ArrayList()   
result.each {  
 def tune = new Tune()  
 tune.playerId = it tune.playerPrice = "100"   
tuneInstanceList.add(tune)  
 }   
def listResult = [total: tunInstanceList.size(), items: tunInstanceList]  
 render listResult as JSON;   

}

如何找回用户输入的参数??

谢谢!

【问题讨论】:

    标签: grails extjs


    【解决方案1】:

    通过读取 list() 操作中的参数并将其保存在会话中来解决此问题。

    然后在 listData() 操作中使用此会话数据进行计算。

    不确定这是否是最好的方法。这只是一种解决方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-19
      • 2017-01-02
      • 2015-08-16
      • 1970-01-01
      • 2015-07-19
      • 1970-01-01
      相关资源
      最近更新 更多