Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
342 views
in Technique[技术] by (71.8m points)

jquery - I'm using bootstraptable treegrid but it failed to load data when using ajax

it loads data successfully when the data is static. But I need the data from the server side and it failed.

code:

var $table=$(“#table”)
var token = $.cookie("gojiajuToken");
    $(function () {
        $table.bootstrapTable(

Here I replace url with a static data,it works perfectly

           url: Store_Service_Url+ "store/custom_category",
            method: "GET",
            idField: "id",
            ajaxOptions: {
                headers: { "Authorization": "Bearer " + token }
            },

The responseHandler receives data successfully

           responseHandler: function (res) {
                console.log("response res")
                console.log(res)
                return res.data
            },
            columns: [{
                field: 'category',
                title: 'name',
                valign: "middle",
                align: "left",
                width: 120

            },     
            {
                field: "id",
                formatter:  "delete2",
                valign: "middle",
                width: 120,
                align: "middle"
            }

            ],              

This part decide the expanded columns and its parent id

         treeShowField:"category",
         parentIdField:"parentID",
            onResetView: function (data) {
                $table.treegrid({
                   
                    initialState: 'expanded',
                    treeColumn: 0,
                    onChange: function () {
                        $table.bootstrapTable('resetWidth');
                    }
                });
             


            }
        })

the sample data will be like

var list = [{
        'category': "test1",
        'comment': "",
        'id': "1”
        'parentID': "",

        'sortIndex': 0
    },
        {
            category: "test2",
           'comment': "",
           'id': "2",
           'parentID': "",
           'sortIndex': 0
        }, {
            category: "test3",
            'comment': "",
            'id': "3",
            'sortIndex': 0
        }]

really need help!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...