I am saving all my data in map and now having trouble accessing them from a separate JS file.
On my (index) page I have 2 tables. The LHS table displays the list of available Instructions, and the RHS will display all the detail information of selected Instructions.
In other words, when the user clicks on the ID#1 on the LHS table, the RHS table will display all the Instructions info for ONLY that ID number.
I've added a onclick function to the ID in my LHS table. Code in index.gsp:
<tbody>
<g:each in="${deliveryInstructions}">
<tr>
<td id="instruction_ID">
<a href="#" onclick="display_DI_details(${it.id})">${it.id}</a>
</td>
<td>${it.deliveryName}</td>
<td>${it.bankName}</td>
...
...
...
</tr>
</g:each>
</tbody>
And in my JS file i have (got the JSON idea from here):
function display_DI_details(id) {
var deliveryID = id;
var deliveryInstructions = ${deliveryInstructions.encodeAsJson()};
document.getElementById('diName').innerHTML = ${deliveryInstructions.deliveryName}
document.getElementById('diID').innerHTML = ${deliveryInstructions.id}
document.getElementById('fundingAccount').innerHTML = ${deliveryInstructions.fundingAccountNumber}
...
...
...
document.getElementById('beneficiary').innerHTML = ${deliveryInstructions.beneficiary}
document.getElementById('comments').innerHTML = ${deliveryInstructions.comments}
}
document.getElementById("display-di-list").innerHTML = display_DI_details(id);
Again in index.gsp this is what I have for the RHS table...
<div id="display-di-list">
<!-- <g:each in="${deliveryInstructions}"> -->
<label>Delivery Name: <p class="receiptData" id="diName"></p></label>
<label>Delivery ID: <p class="receiptData" id="diID"></p></label>
<label>Funding Account: <p class="receiptData" id="fundingAccount"></p></label>
...
...
...
<label>Beneficiary: <p class="receiptData" id="beneficiary"></p></label>
<label>Comments: <p class="receiptData" id="comments"></p></label>
<!-- </g:each> -->
</div>
Finally in the controller file:
def index() {
[deliveryInstructions: DeliveryInstruction.list()]
}
Now I am having trouble to connect few dots to finish this. In my JS file, how do I make it only grab the param values of the passed ID (lets say in this case the ID number is 1)? Thanks a lot for your help & time!!
