Framework7 - 模板概述



描述

Template7 是一個輕量級的、移動優先的 JavaScript 引擎,它將 Ajax 和動態頁面表示為具有指定上下文的 Template7 模板,並且不需要任何額外的指令碼。Template7 與 Framework7 關聯,作為預設的輕量級模板引擎,它可以更快地為應用程式工作。

效能

將字串編譯成 JS 函式的過程是 template7 中最慢的部分。因此,您不需要多次編譯模板,只需編譯一次就足夠了。

//Here initialize the app
var myApp = new Framework7();

// After initializing compile templates on app
var searchTemplate = $('script#search-template').html();
var compiledSearchTemplate = Template7.compile(searchTemplate);

var listTemplate = $('script#list-template').html();
var compiledListTemplate = Template7.compile(listTemplate);

// Execute the compiled templates with required context using onPageInit() method
myApp.onPageInit('search', function (page) {

   // Execute the compiled templates with required content
   var html = compiledSearchTemplate({/*...some data...*/});

   // Do stuff with html
});

Template7 是一個輕量級的模板引擎,用作獨立庫,無需 Framework7。可以使用兩種方法安裝 Template7 檔案:

  • 您可以從 Template7 github 倉庫下載。

  • 或者

  • 您可以使用以下命令透過 Bower 安裝:

bower install template7
廣告