Good Javascript template engine to work with JSON

前端 未结 8 1216
青春惊慌失措
青春惊慌失措 2020-12-06 08:54

I have looked at jTemplates and it\'s worth a try. Are there any other template engines other than jTemplates?

8条回答
  •  情歌与酒
    2020-12-06 09:27

    You can use this one: https://jocapc.github.io/jquery-view-engine/

    It binds properties of JSON object into empty HTML template and match properties with elements by name, id, or class.

    First, you would need to have plain HTML template in your page:

    Then you need JS object that will be placed in template:

    var data = {   Name: "JOVN",
        Desc: "The simplest view engine",
        Tags: ["View engine", "JavaScript", "SPA"]
    }
    

    Finally just fill the view with the data object:

    $("div#template").view(data);
    

    Result is:

    JOVN

    • View engine
    • JavaScript
    • SPA

    View engine will populate single fields or replicate array elements in template.

提交回复
热议问题