2011-04-29 100 views
1

我在模板中選擇了一個模板,並在模型中傳遞i。 $ {i}被替換爲我的值,正如大多數地方所預期的那樣。但$ {i}沒有在onchange事件中被替換。

所以,

<g:select class='setTagtypeValue-class' 
     name='tagtype-${i}-header' 
     from="${org.maflt.ibidem.Tagtype.list(sort:'tagtype').groupBy{it.tagtype}.keySet()}" 
     value="${setTagtypeValue?.tagtype?.tagtype}" 
     noSelection="${['null':'Select One...']}" 
     onchange="${remoteFunction(action:'options', update:'tagtype-options-${i}', 
        params:'\'tagtype=\' + this.value +\'&i=${i}\'')}" /> 

被渲染爲:

<select name="tagtype-0-header" onchange="jQuery.ajax({type:'POST',data:'tagtype=' + this.value +'&amp;i=${i}', url:'/ibidem/metadataSet/options',success:function(data,textStatus){jQuery('#tagtype-options-${i}').html(data);},error:function(XMLHttpRequest,textStatus,errorThrown){}});" class="setTagtypeValue-class" id="tagtype-0-header"> 
<option value="null">Select One...</option> 
<option value="abstract">abstract</option> 
. . . 
</select> 

注意,例如,名稱已定爲 「tagtype-0頭」,但在Onchange我越來越

data:'tagtype=' + this.value +'&amp;i=${i}' 

還要注意的是,當在使用該模板創建,其中substition發生的客戶端,everyt hing按預期工作。所以唯一的問題是,在編輯期間,工作服務器端$ {i}不會在onchange事件中被替換。

任何想法?

回答

1

由於您已經在${}之內,因此內部${}將被忽略。試試這個:

<g:select class='setTagtypeValue-class' 
    name='tagtype-${i}-header' 
    from="${org.maflt.ibidem.Tagtype.list(sort:'tagtype').groupBy{it.tagtype}.keySet()}" 
    value="${setTagtypeValue?.tagtype?.tagtype}" 
    noSelection="${['null':'Select One...']}" 
    onchange="${remoteFunction(action:'options', update:'tagtype-options-' + i, 
       params:'\'tagtype=\' + this.value +\'&i=' + i + '\'')}" /> 
+0

這樣做。不幸的是,爲了避免很多其他的變化,我需要有2個選擇,包裝在。但它的作品! – 2011-04-29 19:00:44