ソースを参照

Improved buttons option

zhixin 5 年 前
コミット
81e9e9467d
2 ファイル変更9 行追加7 行削除
  1. 8 6
      src/bootstrap-table.js
  2. 1 1
      src/utils/index.js

+ 8 - 6
src/bootstrap-table.js

@@ -687,26 +687,28 @@ class BootstrapTable {
       let buttonHtml
 
       if (buttonConfig.hasOwnProperty('html')) {
-        buttonHtml = Utils.calculateObjectValue(opts, buttonConfig.html)
+        if (typeof buttonConfig.html === 'function') {
+          buttonHtml = buttonConfig.html()
+        } else if (typeof buttonConfig.html === 'string') {
+          buttonHtml = buttonConfig.html
+        }
       } else {
         buttonHtml = `<button class="${this.constants.buttonsClass}" type="button" name="${buttonName}"`
 
         if (buttonConfig.hasOwnProperty('attributes')) {
           for (const [attributeName, value] of Object.entries(buttonConfig.attributes)) {
-            buttonHtml += ` ${attributeName}="${Utils.calculateObjectValue(opts, value)}"`
+            buttonHtml += ` ${attributeName}="${value}"`
           }
         }
 
         buttonHtml += '>'
 
         if (opts.showButtonIcons && buttonConfig.hasOwnProperty('icon')) {
-          const icon = Utils.calculateObjectValue(opts, buttonConfig.icon)
-
-          buttonHtml += `${Utils.sprintf(this.constants.html.icon, opts.iconsPrefix, icon) } `
+          buttonHtml += `${Utils.sprintf(this.constants.html.icon, opts.iconsPrefix, buttonConfig.icon) } `
         }
 
         if (opts.showButtonText && buttonConfig.hasOwnProperty('text')) {
-          buttonHtml += Utils.calculateObjectValue(opts, buttonConfig.text)
+          buttonHtml += buttonConfig.text
         }
 
         buttonHtml += '</button>'

+ 1 - 1
src/utils/index.js

@@ -140,7 +140,7 @@ export default {
     return this.cachedWidth
   },
 
-  calculateObjectValue (self, name, args = [], defaultValue) {
+  calculateObjectValue (self, name, args, defaultValue) {
     let func = name
 
     if (typeof name === 'string') {