【问题标题】:How to pass a data like a database data or php constant data to display in a form in main.js如何传递数据库数据或 php 常量数据等数据以在 main.js 中以表单形式显示
【发布时间】:2019-11-14 18:25:47
【问题描述】:

我们构建了一个自定义捆绑包跟随这位讲师https://blog.sulu.io/how-to-develop-a-bundle-in-the-sulu-admin-1 我们需要知道如何从数据库传递数据以呈现单选输入选项或下拉选择。

我们尝试创建一个添加/编辑表单,在表单中,我们在 Vendor/TransportationBundle/Resources/public/js/components/transportation/form/form.html 的 HTML 文件中使用硬核制作了一个单选和下拉列表

代码是

<div class="grid-row">
    <label for="transportation-transportationType"><%= translations.transportationType %></label>
    <div class="custom-radio">
        <input name="transportationType" id="transportation-transportationType-1" type="radio"
               class="form-element content-type" value="1" data-mapper-property="transportationType">
        <span class="icon"></span>
    </div>
    <span class="clickable"><%= translations.private_shuttle %></span>
    <div class="custom-radio">
        <input name="transportationType" id="transportation-transportationType-2" type="radio"
               class="form-element content-type" value="2" data-mapper-property="transportationType">
        <span class="icon"></span>
    </div>
    <span class="clickable"><%= translations.shared_shuttle %></span>
    <div class="custom-radio">
        <input name="transportationType" id="transportation-transportationType-3" type="radio"
               class="form-element content-type" value="3" data-mapper-property="transportationType">
        <span class="icon"></span>
    </div>
    <span class="clickable"><%= translations.airplane %></span>
</div>

这是否有办法改变这些收音机以从数组中获取数据或从某些控制器操作中获取数据?还是有另一种方法来使用具有 twig 功能的 twig 文件而不是 html 文件?

请为我们提供解决方案?谢谢

对不起我的英语。

【问题讨论】:

    标签: sulu aura.js


    【解决方案1】:

    你可以例如检查this Controller from the core。您可以从控制器中的任何位置获取数据并将其传递给模板:

    <?php
    class AcmeController {
        public function testAction() {
            $data = /* Get data somehow */;
    
            return $this->render('template', ['data' => $data]);
        }
    }
    

    然后您可以使用渲染模板中的data twig 变量访问数据。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-04
      • 1970-01-01
      • 2012-05-02
      • 1970-01-01
      • 2022-01-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多