我試圖將driverid
(使用set
)定義爲for driver in assigned.driver
循環中的var以供稍後使用。見下面我在做什麼:小枝:在循環內設置變量,在循環外部使用它
{% for key, assigned in pgn %}
<tr id="device-{{ assigned.id }}">
<td>{{ assigned.imei }}</td>
<td>{{ assigned.description }}</td>
<td>
{% for driver in assigned.driver %}
{{ driver.driver.id }} {# check if driver.driver.id has values testing purposes - delete me #}
{% set driverid = driver.driver.id %}
{% if driver.driver.name != "" %}
{% if driver.driver.name %}
{{ driver.driver.name }}
{% else %}
-
{% endif %}
{% endif %}
{% endfor %}
</td>
<td>
<button class="btn btn-xs btn-default"
onclick="openAlert({{ assigned.id }}, {{ driverid }}, 'unlink')"
data-original-title="{{ "devices.actions.unlink"|trans }}"
title="{{ "devices.actions.unlink"|trans }}">
<i class="fa fa-times"></i>
</button>
<button class="btn btn-xs btn-default"
onclick="openAlert({{ assigned.id }}, null, 'delete')"
data-original-title="{{ "button.delete"|trans }}"
title="{{ "button.delete"|trans }}">
<i class="fa fa-times"></i>
</button>
</td>
</tr>
{% endfor %}
但我得到這個錯誤:
Variable "driverid" does not exist in /var/www/html/src/Device/DeviceBundle/Resources/views/List/listDevices.html.twig at line 74
什麼是設置VAR對openAlert()
電話後使用正確的方法是什麼?或者換句話說,我如何讓driver.driver.id
將它作爲參數傳遞給openAlert()
函數?
完美。謝謝 :) – Zl3n