gpt4 book ai didi

javascript - Twitter Bootstrap 表格可编辑的 json 数据

转载 作者:行者123 更新时间:2023-11-29 10:39:29 25 4
gpt4 key购买 nike

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

<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'
});

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

最佳答案

你错过了 ready 函数,因为这个 jquery 不能绑定(bind)数据。

//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'
});
});

by running the script in console it worked for me

关于javascript - Twitter Bootstrap 表格可编辑的 json 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31551644/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com