0

私の見解では、私は次のことを持っています:

<g:hiddenField name='expandableEducationList[${edIdx}]._deleted' value='false'/>
<button 
                onclick="dojo.byId('expandableEducationList[${edIdx}]._deleted').value='true'; getContainer(this, 'tr').style.display='none'"
                style="width:auto;"
                iconClass="minusIconSmall"
                showlabel="false"
                class="embedded"            
                dojoType="dijit.form.Button"></button>

コントローラーから expandableEducationList を取得するにはどうすればよいですか? 「println params」を実行すると、そこに値が表示されますが、リストを反復処理したいのですが、params.expandableEducationList が null を返しています

値を出力すると、コントローラーに次のように表示されます。

    params?.each{
        println ("it: " + it)
    }

戻り値

it: expandableEducationList[2].type.id=35
it: expandableEducationList[2]=["lastModified_day":"29", "id":"272", "lastModified_year":"2010", "areaOfStudy":"Computer
 Science", "yearGranted":"2008", "lastModified_month":"9", "_deleted":"false", "_inProcess":"", "type":["id":"35"], "col
legeName":"COLLEGE3", "type.id":"35"]
it: expandableEducationList[1]._deleted=false
it: expandableEducationList[1]=["id":"271", "lastModified_day":"29", "lastModified_year":"2010", "areaOfStudy":"Mathemat
ics and Computer Science", "yearGranted":"2009", "lastModified_month":"9", "_inProcess":"", "_deleted":"false", "type":[
"id":"30"], "type.id":"30", "collegeName":"COLLEGE1"]
it: expandableEducationList[2].id=272
it: _action_update=
it: expandableEducationList[1].lastModified_month=9
it: expandableEducationList[2].yearGranted=2008
it: expandableEducationList[1].collegeName=COLLEGE1
it: id=518
it: _expandableEducationList[2].inProcess=
it: expandableEducationListx[0]_name=42
it: expandableEducationList[0].areaOfStudy=Systems Engineering
it: expandableEducationList[0]=["lastModified_day":"29", "id":"270", "lastModified_year":"2010", "yearGranted":"2010", "
areaOfStudy":"Systems Engineering", "lastModified_month":"9", "_deleted":"false", "_inProcess":"", "type":["id":"42"], "
type.id":"42", "collegeName":"COLLEGE2"]
it: expandableEducationList[2].lastModified_day=29
it: expandableEducationList[0].id=270
it: expandableEducationList[2]._deleted=false
it: expandableEducationList[0].lastModified_day=29
it: geographicPreferences=
it: expandableEducationList[2].areaOfStudy=Computer Science
it: expandableEducationList[2].collegeName=COLLEGE3
it: expandableEducationListx[1]_name=30
it: expandableEducationList[1].lastModified_day=29
it: _expandableEducationList[0].inProcess=
it: _expandableEducationList[1].inProcess=
it: expandableEducationList[0]._deleted=false
it: expandableEducationList[1].yearGranted=2009
it: expandableEducationList[1].lastModified_year=2010
it: expandableEducationList[2].lastModified_month=9
it: expandableEducationList[1].areaOfStudy=Mathematics and Computer Science
it: expandableEducationList[2].lastModified_year=2010
it: expandableEducationList[1].id=271
it: expandableEducationListx[2]_name=35
it: expandableEducationList[0].yearGranted=2010
it: expandableEducationList[0].lastModified_month=9
it: expandableEducationList[0].collegeName=COLLEGE2
it: expandableEducationList[0].lastModified_year=2010
it: expandableEducationList[0].type.id=42
it: expandableEducationList[1].type.id=30
4

3 に答える 3

0

次のように名前を割り当てます。 name='expandableEducationList[${edIdx}]._deleted'

params オブジェクトには、文字どおり「expandableEducationList[1]._deleted」などの名前のパラメーターが取り込まれますが、インデックスでアクセスできる「expandableEducationList」という名前のリストではありません。

同じトピックの他の StackOverflow スレッド:

リンクされたスレッドが最適に機能する可能性があるため、最初にリンクされたスレッドを確認してください。

アイテムの数とプロパティの名前がわかっている場合は、別の解決策を次に示します。

//count is the number of items 
def expendableEducationList=(0..count).collect{
    index->
    // propNames is a list of names such as ['_.deleted', 'areaOfStudy', etc..] 
    // returns a new map with each property value
    propNames.inject([:],{
        map, prop->
        map[prop]=params["expandableEducationList[$index].$prop"]
        return map
    } 
}
于 2010-11-14T05:59:07.910 に答える
0

gsp をレンダリングしているコントローラー アクションのモデルの一部として渡します。

このような...

[expandableEducationList: ExpandableEducation.list()]

またはこのようなもの..

  render(view: 'viewName', 
         model: [expandableEducationList: ExpandableEducation.list()])
于 2010-10-29T18:36:17.660 に答える
0

これを行う "Grailsy" の方法は、コマンド オブジェクトとデータ バインディングを使用することです。こちらのデータ バインディングと多端の関連付けを ご覧ください。

これにより、アソシエーションにマップするCommandオブジェクトを作成し、次のようなものを使用してリクエスト パラメータをバインドできます。

def command = new MyCommand()
bindData(command, params)

これは、アーロンの回答に関するコメントで言及したソリューションの代替ソリューションにすぎません。

于 2010-10-29T19:00:52.740 に答える