feat: 能够自定义数据表主键列名

#Comment
smartTable: {
            idField: ‘DictId’,
            sortName: 'Category',
            columns: [ ]
}
This commit is contained in:
Argo Zhang 2019-05-21 20:27:53 +08:00
parent 16ec57577b
commit 6626162e71
1 changed files with 13 additions and 4 deletions

View File

@ -7,6 +7,12 @@
return data; return data;
}; };
var findIdField = function (tableName) {
var idField = $(tableName).bootstrapTable("getOptions").idField;
if (idField === undefined) idField = "Id";
return idField;
}
DataEntity = function (options) { DataEntity = function (options) {
this.options = options; this.options = options;
}; };
@ -159,13 +165,15 @@
confirmButtonClass: "btn-danger ml-2", confirmButtonClass: "btn-danger ml-2",
cancelButtonText: "取消" cancelButtonText: "取消"
}, function () { }, function () {
$.logData.push({ url: options.url, $.logData.push({
url: options.url,
data: arrselections.map(function (element, index) { data: arrselections.map(function (element, index) {
return formatData($.extend({}, element)); return formatData($.extend({}, element));
}) })
}); });
setTimeout(function () { setTimeout(function () {
var iDs = arrselections.map(function (element, index) { return element.Id; }); var idField = findIdField(options.bootstrapTable);
var iDs = arrselections.map(function (element, index) { return element[idField]; });
$.bc({ $.bc({
url: options.url, data: iDs, method: 'delete', title: options.delTitle, url: options.url, data: iDs, method: 'delete', title: options.delTitle,
callback: function (result) { callback: function (result) {
@ -238,8 +246,9 @@
}, function () { }, function () {
$.logData.push({ url: op.url, data: data }); $.logData.push({ url: op.url, data: data });
setTimeout(function () { setTimeout(function () {
var idField = findIdField($(op.table));
var iDs = data.map(function (element, index) { var iDs = data.map(function (element, index) {
return element.Id; return element[idField];
}); });
$.bc({ $.bc({
url: op.url, data: iDs, method: 'delete', title: '删除数据', url: op.url, data: iDs, method: 'delete', title: '删除数据',