문제

I have a django view, and this view returns a table which is populated asynchronously with an ajax call.

From the design point of view, which one should I follow:

  1. the django view, called via ajax, returns the content of the table as a json response, containing html markups for each cell. The javascript callback handler takes the contents and slaps them untouched into the table cells.
  2. the django view, called via ajax, returns pure data about what should go into the table, again as a json response. The async javascript callback takes the data, formats them with proper markup, and puts it into the table.

In other words, who should have the responsibility for markup formatting of the cell contents? the view or the javascript ?

I would be tempted to say the first, since the view already returns marked up content. If it returns a json containing marked-up content, there's not much difference.

I would like to hear your point of view.

올바른 솔루션이 없습니다

다른 팁

If you're populating the whole table, you can put your table in its own template and return the table's html via ajax/json.

You'll need to edit the original template to include the table template:

 {% include "myapp/_table.html" %}

And in the view, return the rendered template as a json variable, which your javascript will substitute in:

 return { 'table': render_to_string("myapp/_table.html", context) }

This approach is good where you always want to update the entire table, and the rendering of the table doesn't require the full context. I'm not sure what the performance is like, but it is a clean way of updating part of the page, because you only define your table once.

It depends (as so often).

If the data is requested only here and now, it would be easier and less error prone to just let it render on server-side with the same set of templates that already rendered the standard view.

If you could think of use cases however, where the data would be needed in other places (like auto-complete fields), it would be better to let JavaScript do the job and create a clean, reusable JSON export.

These options add to all the other answers, and finally it's up to you to decide.

아래 스크립트를 사용 해보십시오

Enable-SPFeature –identity a44d2aa3-affc-4d58-8db4-f4a3af053188 -URL http://[UR Site URL]
.

아래 링크를 살펴보십시오.

특징그리고 그들의 GUID는 SP2010

It is a good to practice Unabstrusive javascript, also called by some people as Hijax

So, you first have a standard page, that presents the table along with the rest of the page, with table in a particular django-template block.

Once you have this, you can include the extends part of the django template within an "if not ajax", so you only get the required table part in the ajax response which you can load in the client to the required div.

It is un-necessary and redundant to maintain the markup twice once at the server and once at the client, in javascript.

hence, I'd prefer the first option, of server redering, and client only loading the rendered html.

I've come across this several times before, and I generally opt for the latter, where the view returns pure JSON.

However, the approach you choose should definitely depend on several factors, one of which is targeted devices (and their CPU/network constraints). Pure JSON will generally result in smaller payloads and so may be optimal for mobile devices.

It may also make sense to expose both HTML and JSON versions of your content. This is especially helpful if you're looking to create a very lightweight API at some point for your site.

Finally, you can use a library such as John Resig's micro-templating or Closure Templates to simplify client-side HTML generation.

SharePoint 2010 로깅은 ULS 및 이벤트 로그에서 수행 할 수 있습니다. spdiagnosticsservice 클래스를 사용합니다.클래스는 두 가지 방법을 제공합니다 WriteTrace 및 WriteEvent는 ULS 및 이벤트에 흔적과 이벤트를 작성합니다. 각각 뷰어.우리는 또한 SpdiagnosticsServiceBase 클래스에서 상속하여 자체 사용자 정의 영역 및 범주를 만들 수 있습니다.

public class LoggingService : SPDiagnosticsServiceBase
{
    private const string AREA = "Custom Diagonostic Area";
    private const string CATEGORY = "Custom Diagonostic Category";
    private static readonly LoggingService current;

    public static LoggingService Current
    {
        get
        {
            return LoggingService.current;
        }
    }

    static LoggingService()
    {
        LoggingService.current = new LoggingService();
    }

    private LoggingService()
        : base("Custom Logging Service",SPFarm.Local)
    {
    }

    protected override IEnumerable<SPDiagnosticsArea> ProvideAreas()
    {
        List<SPDiagnosticsArea> areas = new List<SPDiagnosticsArea>
        {
            new SPDiagnosticsArea(LoggingService.AREA, new List<SPDiagnosticsCategory>
            {
                new SPDiagnosticsCategory(LoggingService.CATEGORY,TraceSeverity.Monitorable,EventSeverity.Error)
            })
        };

        return areas;
    }

    public static void LogErrorToULS(TraceSeverity severity, string errorMessage)
    {
        SPDiagnosticsCategory category = LoggingService.Current.Areas[LoggingService.AREA].Categories[LoggingService.CATEGORY];
        LoggingService.Current.WriteTrace(0, category, severity, errorMessage);
    }

    public static void LogErrorToEventViewer(EventSeverity severity, string errorMessage)
    {
        SPDiagnosticsCategory category = LoggingService.Current.Areas[LoggingService.AREA].Categories[LoggingService.CATEGORY];
        LoggingService.Current.WriteEvent(0, category, severity, errorMessage);
    } 
}
.

"Nofollow"> SharePoint 2010 진단 로깅 참조 용

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top