如果存储在数据库中的数据是 Json 响应的结果,如何在 select2 中检索数据

how to retrieve data in select2, if the data stored in the database is the result of Json response

你好我有一些问题,我有一个问题,我想在 select2 中显示数据,但这里的问题是存储在数据库中的数据是 json 的响应这是我会做出回应。

{
"name": "BCA",
"type": "bank",
"properties": "{\"data\": {\"id\": 1, \"nickname\": \"\", \"products\": [{\"id\": 1, \"number\": \"0011223344\"}]}, \"status\": \"success\"}",
}

我想在 select2

中得到 number

有我的 select2 代码

 $('#name').select2({
  placeholder: "Choose User...",
  ajax: {
    url: "{{ route('somemyroute') }}",
    dataType: "json",
    delay: 250,
    processResults: function(data) {
      return {
        results: $.map(data, function(obj) {
          return {
            id: obj.user_id,
            text: obj.name+" | "+obj.properties.data.products.number
          };
        })
      };
    },
  }
});

但是出现这样的错误 jQuery.Deferred 异常:

Cannot read property 'number' of undefined TypeError: Cannot read property 'number' of undefined

请确保所有数据都包含产品数组。有些元素可能不会,因此您会收到此错误。

另请注意,产品是一个元素数组,因此您需要引用数组中您想要 select 数字

的项目