当前位置: 移动技术网 > IT编程>开发语言>JavaScript > 关于bootstrap日期转化,bootstrap-editable的简单使用,bootstrap-fileinput的使用详解

关于bootstrap日期转化,bootstrap-editable的简单使用,bootstrap-fileinput的使用详解

2018年05月02日  | 移动技术网IT编程  | 我要评论

数据库中为datetime类型,.net读取数据已json格式发回给前台页面:例如:使用bootstrap表格插件ⅹ

 formatter: function (value, row, index) {
            var date = new date(parseint(value.slice(6)));
            return date.getfullyear() + '-' + parseint(date.getmonth() + 1) + '-' + date.getdate() + " " + date.gethours() + ":" + date.getminutes()+":"+date.getseconds();
          }

使用bootstrap-editable时需要引用

<script src="~/scripts/bootstrap3-editable/js/bootstrap-editable.min.js"></script>
<script src="~/scripts/bootstraptable/dist/extensions/editable/bootstrap-table-editable.min.js"></script>

初始化时:

{
          field: 'skupurchaseprice',
          title: '采购价',
          align: 'center',
          editable: {
            type: 'text',
            title: '采购价',
            validate: function (v) {
              if (v < 0) return '采购价不能小于0';
            }
          }
        }, {
          field: 'qtyavailable',
          title: '库存可用量',
          align: 'center',
          editable: {
            type: 'text',
            title: '库存可用量',
            validate: function (v) {
              if (v < 0) return '库存可用量不能小于0';
            },           
          },          
        }

事件:

oneditablesave: function (field, row, oldvalue, $el) {
          $.ajax({
            type: 'post',
            url: "@url.action("editnumber")",
            datatype: 'json',
            data: { "row": json.stringify(row) },
            success: function (data) {
              if (data.resulttype == 0) {
                toastr.success(data.message);
              }
              else {
                toastr.warning(data.message);
              }
            },
            error: function () {
              toastr.error("出错了,请联系管理员");
            }
          });
        }

bootstrap-fileinput使用:

引用

<script src="~/scripts/adminlte2.3.0/bootstrap/js/fileinput.min.js"></script>

初始化:

 <label class="control-label col-sm-1">商品上传</label>
              <div class="col-sm-2"><input type="file" id="productsupload" name="productsupload" /></div>
              <div class="col-sm-1"><a href="~/productsexcel/downloadtemplate?type=5" rel="external nofollow" target="_blank">下载模板</a></div>
function initfileinput(ctrlname) {
      var control = $('#' + ctrlname);
      control.fileinput({
        language: 'zh', //语言
        uploadurl: "@url.action("excelleadingin")", //action
        autoreplace: true,
        maxfilecount: 1, //最大上传数量
        allowedfileextensions: ["xlsx", "xls"],
        browseclass: "btn btn-primary", //按钮样式
        dropzoneenabled: false,
        enctype: 'multipart/form-data',
        showremove: true, //是否显示删除按钮
        showbrowse: true, //显示浏览图片按钮
        msgfilestoomany: "选择上传的文件数量({n}) 超过允许的最大数值{m}!",
        msginvalidfileextension:"只支持.xlsx和.xls文件的格式上传",
        fileactionsettings: {
          showupload: false, //预览图片上传按钮
          showremove: false, //预览图片remove按钮
          showzoom: false //关闭预览图片按钮
        }
      }).on('fileuploaded', function (event, data, previewid, index) {//上传图触发事件
        if (data.response.state == 1) {
          $('#excellendingdiv h5').html($('#excellendingdiv h5').html() + data.response.result+"<br/>");
        }
        else {
          toastr.error(data.response.result);
        }
      }).on('filecleared', function (event) {//remove触发事件
        control.show();
      });
    }

 后台上传:

 [httppost]
    public actionresult excelleadingin()
    {     
      var files = request.files;
      string name=files.keys[0].tostring();
      if (files != null && files.count > 0)
      {       
        var file = files[0];        
        string path = server.mappath("~/content/excel/") + file.filename;//文件保存在当前域名下的content/excel/中
        file.saveas(path);       
        string mess = offerserver.productsdetail.insertexcel(path,file.inputstream,name);
        return json(new { state = 1, result = mess });
      }
      return json(new { state = 0, result = "上传发生错误,请检查后重试" });
    }

以上所述是小编给大家介绍的关于bootstrap日期转化,bootstrap-editable的简单使用,bootstrap-fileinput的使用详解,希望对大家有所帮助

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网