-1

チェックボックスIDをgrailsの他のフィールドの値にマッピングするためのJavaScript関数が必要です

私は次のようにチェックボックスとコストフィールドを持つgspページを持っています

<td>
                    <g:checkBox type="checkbox" class="select_all" name="counTestUnit" id="${testUnitInstance.id}" />
                    </td>


                    <td>
                        <g:textField name="cost"  maxlength="20" required="" id="${testUnitInstance.id}"  />
                    </td>

チェックされたチェックボックス ID とコスト フィールドをマッピングする JavaScript 関数が必要です

4

2 に答える 2

0

以下のようにできます

<td>
                    <g:checkBox type="checkbox" class="select_all" name="counTestUnit" id="checkbox${testUnitInstance.id}" onclick="mapCheckAndField(${testUnitInstance.id})"/>
                    </td>


                    <td>
                        <g:textField name="cost"  maxlength="20" required="" id="textField${testUnitInstance.id}"  />
                    </td>
<script>
function mapCheckAndField(testUnitId)
{
   //we know that now checkboxId is "checkbox"+testUnitId
   //and corresponding textField id is "textField"+testUnitId
   //Simply you will get the value of checkbox corresponding textField value as below
   $("#textField"+testUnitId).val()
}
</script>
于 2013-09-13T08:41:17.673 に答える
0

チェックボックスの変更時機能が必要であり、id に intital を追加してコスト テキスト フィールドと区別する必要があります。後で intital が ID に続くため、その ID を抽出して対応するコスト フィールドを見つけます。

"c_${testUnitInstance.id}"

<g:checkBox type="checkbox" class="select_all" name="counTestUnit" id="c_${testUnitInstance.id}" onChange="FindCost('c_${testUnitInstance.id}')"/>

<g:javascript>    

function FindCost(chckboxname){  
console.log("check Status:"+$("#"+chckboxname).prop("checked"));
var arrayOfchckBoxId = chckboxname.split("_"); //parse the two parts of the name after _

var commnidforcheckandcost = arrayOfchckBoxId[1];

var initialname = arrayOfchckBoxId[0];

var currentCheckbox = "#"+chckboxname ;

console.log("ID:"+arrayOfchckBoxId[1]);
console.log("Name:"+currentCheckbox);

if(initialname == 'c'){
//display the corresponsing cost text field.

$("#"+commnidforcheckandcost").show() //display the cost with a give id like checkbox

 }

</g:javascript>

これで問題が解決するはずです。詳細については、javascript コンソールのデバッグを参照してください。

于 2013-09-13T07:06:10.887 に答える