我的表中有“多项选择”值,当我尝试将其发布到数据表中时,它显示“未找到匹配的记录”。我正在使用“ json_encode”将数组发布到数据库。
我的桌子看起来像这样。
我的tb_produc:
class OrdersListView(ListView, BaseLoginRequiredMixin):
template_name = 'billing/orders.html'
paginate_by = 10
form_class = billing_forms.OrdersForm
model = Order
def get_queryset(self):
return billing_orders.list_orders(owner=self.request.user)
我的tb_categories:
+------------+--------------+---------------+------------+
| id_product | name_product | id_categories | price |
+--------------------------------------------------------+
| 1 | cola | ["1","3"] | 1 |
| 2 | burger | ["2","3"] | 4 |
+--------------------------------------------------------+
当我尝试在连接表之后在数据表上显示它时,它说“没有找到匹配的记录”。
型号:
+------------+--------------+
| id_cat | name_cat |
+---------------------------+
| 1 | drink |
| 2 | food |
| 3 | fat |
+---------------------------+
控制器:
function get_all_product() {
$this->datatables->select('id_product, name_product, name_cat, price');
$this->datatables->from('tb_product');
$this->datatables->join('tb_stock', 'id_categories=id_cat');
$data = $this->datatables->generate();
视图:
function get_product_json() {
header('Content-Type: application/json');
echo $this->m_table->get_all_product();
}
js:
<tr>
<th>Id</th>
<th>Product Name</th>
<th>Categories</th>
<th>Price</th>
</tr>
其他不使用“多选”的数据表可以正常工作,但不能正常使用。
我想要的数据表结果是这样的。
var table = $("#fproduk").dataTable({
'aoColumnDefs': [{
'bSortable': false,
'aTargets': -1
}],
initComplete: function() {
var api = this.api();
$('#fproduk_filter input')
.off('.DT')
.on('input.DT', function() {
api.search(this.value).draw();
});
},
oLanguage: {
sProcessing: "loading..."
},
processing: true,
serverSide: true,
ajax: {"url": "../datatable/get_produk_json", "type": "POST"},
columns: [
{"data": "id_product"},
{"data": "name_product"},
{"data": "name_cat"},
{"data": "price", render: $.fn.dataTable.render.number(',', '.', '')}
],
order: [[1, 'asc']],
rowCallback: function(row, data, iDisplayIndex) {
var info = this.fnPagingInfo();
var page = info.iPage;
var length = info.iLength;
$('td:eq(0)', row).html();
}
});
感谢您的关注。