4-15总结

1.把html表格进行行列转置

function TransposeTable(tableId){

var tbl = $('#' + tableId);

var tbody = tbl.find('tbody');

var oldWidth = tbody.find('tr:first td').length;

var oldHeight = tbody.find('tr').length;

var newWidth = oldHeight;

var newHeight = oldWidth;

var jqOldCells = tbody.find('td');

var newTbody = $("<tbody></tbody>");

for(var y=0; y<newHeight; y++)

{

var newRow = $("<tr></tr>");

for(var x=0; x<newWidth; x++)

{

newRow.append(jqOldCells.eq((oldWidth*x)+y));

}

newTbody.append(newRow);

}

tbody.replaceWith(newTbody);

}

可以实现表格行列的转置。

例如

项目 时间

项目1 2012

可以转成

项目 项目1

时间 2012

反之也是可以的。这样当需要某种类型的表格的时候,就不需要对于数据源的调整,而且,其实数据源很不好调整,循环很麻烦的。解决方案来自:https://stackoverflow.com/questions/2730699/convert-td-columns-into-tr-rows

2.使用Nlog和action过滤器记录web请求参数和结果。

public class ActionFilter : ActionFilterAttribute
    {
        private Logger logger = LogManager.GetCurrentClassLogger();
        public override void OnActionExecuting(ActionExecutingContext actionContext)
        {
            //记录请求参数
            logger.Debug("请求参数:"+JsonConvert.SerializeObject(actionContext.ActionArguments));
        }
        public override void OnActionExecuted(ActionExecutedContext actionExecutedContext)
        {
            //记录返回数据
            logger.Debug("请求结果:"+ JsonConvert.SerializeObject(actionExecutedContext.Result));

        }

    }

.net core 的过滤器使用

这里是action过滤器 继承 ActionFilterAttribute
OnActionExecuting action执行之前调用
OnActionExecuted action执行之后调用

using FiltersSample.Helper;
using Microsoft.AspNetCore.Mvc.Filters;

namespace FiltersSample.Filters
{
    public class SampleActionFilter : IActionFilter
    {
        public void OnActionExecuting(ActionExecutingContext context)
        {
            // do something before the action executes
        }

        public void OnActionExecuted(ActionExecutedContext context)
        {
            // do something after the action executes
        }
    }
}

猜你喜欢

转载自blog.csdn.net/MannMann/article/details/89316325