3

为什么我不能以这种方式使用引导可编辑表?

<table id="addElements" data-height="299">
    <thead>
        <tr>
            <th data-field="id" data-align="right">Item ID</th>
            <th data-field="element" data-align="center">Element</th>
            <th data-field="weight" data-align="">Težina</th>
            <th data-field="default_thickness" data-align="">Debljina</th>
        </tr>
    </thead>
</table>


    //put data in js variable and fill the table
var elementData = [{
    "id": "1",
    "element": "c",
    "weight": "20",
    "default_thickness": "6"
}, {
    "id": "2",
    "element": "k",
    "weight": "21",
    "default_thickness": "2"
}, {
    "id": "3",
    "element": "p",
    "weight": "18",
    "default_thickness": "2"
}];
$(function () {
    $('#addElements').bootstrapTable({
        data: elementData
    });
})

$.fn.editable.defaults.mode = 'inline';
    $('td').editable({
            url: '/post',
            type: 'text',
            pk: 1,
            name: 'parket',
            title: 'Enter username'
        });

在这个小提琴 https://jsfiddle.net/aleksacavic/03agu1ex/1/ 它工作,当点击时,表格单元格处于编辑模式。但是我网站上的相同代码不起作用?我错过了什么?正如我所看到的,在我这边,当单击时,单元格不允许更改类,只有表线程被突出显示,没有创建附加元素(输入字段)。谢谢

4

2 回答 2

3

您错过了就绪功能,因为这个 jquery 无法绑定数据。

//put data in js variable and fill the table
$(window).bind("load", function() {
    var elementData = [{
        "id": "1",
        "element": "c",
        "weight": "20",
        "default_thickness": "6"
    }, {
        "id": "2",
        "element": "k",
        "weight": "21",
        "default_thickness": "2"
    }, {
        "id": "3",
        "element": "p",
        "weight": "18",
        "default_thickness": "2"
    }];
    $(function () {
        $('#addElements').bootstrapTable({
            data: elementData
        });
    })


$.fn.editable.defaults.mode = 'inline';
        $('a').editable({
            url: '/post',
            type: 'text',
            pk: 1,
            name: 'parket',
            title: 'Enter username'
        });
    $('td').editable({
            url: '/post',
            type: 'text',
            pk: 1,
            name: 'parket',
            title: 'Enter username'
        });
});

通过在控制台中运行脚本它对我有用

于 2015-07-22T09:50:58.937 回答
0

尝试添加加载延迟,应该修复它:

setTimeout(function(){
            $.fn.editable.defaults.mode = 'inline';
            var a = $('a');
            $('a').editable({
                type: 'text',
                pk: 1,
                name: 'parket',
                title: 'Enter username'
            });
            $('td').editable({
                type: 'text',
                pk: 1,
                name: 'parket',
                title: 'Enter username'
            });
        },500);
于 2015-09-01T17:24:03.417 回答