0

我想使用“类型”列值过滤行。它来自名为 article 的子对象。我无法直接访问该属性。我需要使用数组键row.articles.type

我可以使用取决于 is_suspend 列的状态进行过滤,我可以轻松访问 is_suspend 说row.is_suspended。但它涉及子对象值,它不会过滤..

一件物品的样子;

{
id: 7,
user_id: 11,
article_id: 216,
content: "Rerum velit soluta quos provident corporis eum dolores. Dolorem ex deleniti quisquam. Voluptas eum sint itaque quibusdam vel. Non sit alias cumque doloribus aut.",
created_at: "2018-09-14 21:22:53",
updated_at: "2018-09-14 21:22:53",
is_suspend: 0,
user: {
       id: 11,
       name: "Mayra Rau",
       username: "edgar.schmeler",
       email: "leuschke.kraig@example.org",
       created_at: "2018-09-11 00:15:47",
       updated_at: "2018-09-11 00:15:47",
       suspended_at: null,
       banned_at: null,
       points: "3772"
},
article: {
         id: 216,
         locale: "fr",
         content: "Qui earum repudiandae aliquam et ab aut maxime. Debitis alias voluptatum voluptate ut ut. Repellendus asperiores ut rem aut et voluptates eum. Sed voluptatem repellat maiores. Dolores commodi laboriosam voluptatem deserunt reprehenderit.",
         articleable_id: 72,
         articleable_type: "App\Models\Cpu",
         type: "Cpu",
         articleable: {
                      id: 72,
                      title: "AMD A4-9120",
                      slug: "amd-a4-9120"
                      }
         }
},

字段部分

{
    field: "type",
    title: "Type",
    width: 70,

    template: function (row) {
    var status = {
        Cpu: {'title': 'CPU', 'class': 'm-badge--info'},
        Gpu: {'title': 'GPU', 'class': ' m-badge--default'},
        Mb: {'title': 'MB', 'class': ' m-badge--warning'},
    };
    return '<span class="m-badge '+status[row.article.type].class+' m-badge--wide">'+status[row.article.type].title+'</span>';
}

},

过滤器部分

$('#m_form_type').on('change', function () {
    datatable.search($(this).val(), 'type');
}).val(typeof query.Type !== 'undefined' ? query.Type : '');
4

0 回答 0