javascript - 如何将数据显示为不同数据库表的选项

标签 javascript html laravel vuejs2 laravel-5.7

我正在使用Laravel 5.7 & VueJs 2.5.* .我正在构建一个发票应用程序。

我有一个表 Vendors并且需要显示全部Vendors在我的创建发票表单中(例如,此发票与所选的 Vendor 相关)。

这是我的<script>代码:

<script>
  export default {
    data() {
      return {
        ticketInvoices: {},
        ticketInvoiceItems: [],
        form: new Form({
          id: "",
          vendor_id: "",
          ticket_invoice_no: "",
          ticket_invoice_date: "",
          ticket_invoice_grand_total: "",
        })
      };
    },
    methods: {
      addItems() {
        this.ticketInvoiceItems.push({
          id: "",
          passenger_name: "",
          ticket_no: "",
          flight_no: "",
          departure_date: "",
          sub_total: ""
        });
      },
      removeItems(pos) {
        this.ticketInvoiceItems.splice(pos, 1);
      },
      </script>

需要显示Vendor在此列出:

<div class="form-group">
  <label for="vendor">Select Vendor</label>
  <select class="form-control" :class="{ 'is-invalid': form.errors.has('vendor') }">
    <option value="" disabled selected>Please Select Vendor</option>
    <option>All Vendors Name</option>
  </select>
  <has-error :form="form" field="vendor"></has-error>
</div>

最佳答案

我假设您有一个返回所有 vendor 数据的 Controller 。类似的东西;

public function index()
{
   $vendors = Vendor::all();
   return $vendors;
}

这将返回所有 vendor 的 JSON 响应。

在你的 html 代码中,你可以这样做;

<div class="form-group">
    <label for="vendor">Select Vendor</label>
    <select class="form-control" :class="{ 'is-invalid': form.errors.has('vendor')}">
        <option value="" disabled selected>Please Select Vendor</option>
        <option v-for="vendor in vendors">{{ vendor }}</option>
    </select>
    <has-error :form="form" field="vendor"></has-error>
</div>

在你的 Vue 代码中;

data () {
    return {
      vendors: null
    }
},
mounted () {
axios
  .get('https://example.com/api/vendors')
  .then(response => (this.vendors = response))
}

关于javascript - 如何将数据显示为不同数据库表的选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52946563/

相关文章:

html - 使超大屏幕背景图像和文本响应

php - 特殊搜索表单

javascript - 在 mouseleave 上保持 Twitter Bootstrap 工具提示打开

javascript - 重新触发 Javascript 事件是否安全?

javascript - 如何在javascript中获取名称中带有点的属性的值?

javascript - 如何让div中的图像保持宽高比

php - 如何修复 Laravel 5.7 中的 "Invalid datetime format: 1366 Incorrect integer value: "错误?

php - Laravel - Sentinel 用户与 eloquent 用户不同

php - 为什么我无法在 Laravel 5.1 中上传到 public_html?

javascript - HTML 导入在 Electron 应用程序中不起作用