php - Opencart 3.0.3.2 - 在 Ajax + Twig 上抓取多维数组
问题描述
美好的一天,我在尝试获取 admin/view/template/catalog/product_form.twig ajax 函数上的数组以将其显示为自定义时遇到了一些麻烦<select>
,该数组由autocomplete()
admin/controller/catalog/option.php 上的函数给出,新的数组值存储在'parent_option_value' => $parent_option_value_data
. 我一直在乱改诸如$('#option-values' + option_row)
to$('#parent-option-values' + option_row)
和其他元素之类的东西,但没有成功。
新的array()确实获得了数据,但我无法在第一个上显示它的值<select>
。我需要添加和更改以使该数组显示为第二个选项值<select>
吗?
管理员/视图/模板/目录/product_form.twig
<!-- The Array I Need -->
if (parent_option_id > 0) {
html += ' <td class="text-left"><select name="product_option[' + option_row + '][product_option_value][' + option_value_row + '][option_value_id]" class="form-control">';
html += $('#option-values' + option_row).html();
html += ' </select><input type="hidden" name="product_option[' + option_row + '][product_option_value][' + option_value_row + '][product_option_value_id]" value="" /></td>';
}
<!--/ The Array I Need /-->
html += ' <td class="text-left"><select name="product_option[' + option_row + '][product_option_value][' + option_value_row + '][option_value_id]" class="form-control">';
html += $('#option-values' + option_row).html();
html += ' </select><input type="hidden" name="product_option[' + option_row + '][product_option_value][' + option_value_row + '][product_option_value_id]" value="" /></td>';
管理员/控制器/目录/option.php
public function autocomplete() {
...
if ($option['parent_id'] > 0) {
$json[] = array(
'parent_option_id' => $option['parent_id'],
'option_id' => $option['option_id'],
'name' => strip_tags(html_entity_decode($option['name'], ENT_QUOTES, 'UTF-8')),
'category' => $type,
'type' => $option['type'],
'parent_option_value' => $parent_option_value_data,
'option_value' => $option_value_data
);
} else {
$json[] = array(
'parent_option_id' => $option['parent_id'],
'option_id' => $option['option_id'],
'name' => strip_tags(html_entity_decode($option['name'], ENT_QUOTES, 'UTF-8')),
'category' => $type,
'type' => $option['type'],
'option_value' => $option_value_data
);
}
}
...
解决方案
推荐阅读
- python - 熊猫日期时间转换将 .0 添加到列值
- python - 在列表上迭代函数
- swift - 模拟 AVCaptureDeviceInput 进行测试
- javascript - 加载模块时highcharts组织结构图抛出错误
- node.js - Jest 内存泄漏测试 Express 中间件
- flutter - 将从相机捕获的图像保存到图库中
- groovy - 方法没有签名:*** 适用于参数类型:() 值:[] 可能的解决方案:getRandomShippingMethod()
- r - 如何在 RMarkdown 中使用 Shiny 进行嵌套选择 selectInput()?
- python - 从源代码编译后让 OpenCV 与 python 一起工作
- spring-batch - Spring Partitioning:有没有办法对 SQL 读取器、非连续列值进行分区 - 所以线程具有唯一记录?