I have a jquery function that is mixed with twig data:
$(document).on('change', '.item-select', function() {
var optionValue = $(this).val();
{% for key, value in columns_arr %}
{% for k,v in group %}
if (optionValue == "{{ v.id }}") {
{% set output = v %}
{% for method in value|split('.') if method != '' %}
{% set output = attribute(output, method) | default('') %}
{% endfor %}
var {{ value | split('.') | first }} = "{{ output }}";
}
{% endfor %}
{% endfor %}
if (optionValue) {
var entity = $(this).find(':selected').attr('data-parent');
var relation = $(this).find(':selected').attr('data-slug');
var uuid= $(this).find(':selected').attr('data-id');
table.row.add({
{% for key, value in columns_arr %}
{% for k,v in group %}
"{{ value | split('.') | first }}": {{ value | split('.') | first }},
{% endfor %}
{% endfor %}
}).draw();
$('option', this).first().prop('selected', true);
fetch(`/row/${entity}/${relation}/${uuid}/${optionValue}`,{
method: 'POST'
}).then(res => window.location.reload());
}
});
I get the error message:
An exception has been thrown during the rendering of a template ("Catchable Fatal Error: Object of class Proxies__CG__\App\Entity\Productgroup could not be converted to string").
And the error should be in this line:
var {{ value | split('.') | first }} = "{{ output }}";
column_arr
looks like? It seems it is an array ofProductgroup
entities. You should call the specific field of them ({{ value.name | split('.') | first }}
for example) or give these entities a__toString
method. – Wulfarray:4 [▼ 0 => "id" 1 => "name" 2 => "productgroup" 3 => "category.name" ]
– peace_loveproductgroup
by changing the column definition. e.gproductgroup.name
– DarkBeearray:4 [▼ 0 => "id" 1 => "name" 2 => "productgroup.name" 3 => "category.name" ]
instead ofarray:4 [▼ 0 => "id" 1 => "name" 2 => "productgroup" 3 => "category.name" ]
I think this is where I need to make the fix – peace_love