nested template rendering in backbone.js

I have a template like

script type: "text/template", id: "list-template", '''    
    
<input class="list-input" type="text" value="" /> <input id="hdnListId" type="hidden" value="" />
'''

in this template i have


    element in which i want to render another template which display list inside this ul. this template is :

    script type: "text/template", id: "card-template", '''    
        
    '''

    is it possible or i have to do it in another way? please help me if anyone have idea. thanks in advace.

    it is worked but still i have one problem in data display in


      there sholud be 2

    • as per records in my database but it will display only 1
    • . data fetch properly but display only last data.

      Problem courtesy of: priyanka patel

    • Solution

      There are two ways to do this: the DOM way and the template way.

      The DOM way involves adding your views using DOM methods: you have your ListView and your CardView; the ListView invokes individual CardViews that fill in the ListView’s element.

      The template way requires that you remember this: backbone’s views are policy frameworks, not policy templates. Render doesn’t have to render into the DOM
      . You can use render()
      to return a string, for example. If your event manager is on the ListView object only (possible; I’ve done this), then you can have ListView invoke “the resulting array of an array of CardView renders” and insert that directly into ListView’s template. This is actually faster, as you only require the browser to analyze the entire ListView HTML blob once, when it’s inserted into the innerHTML of the parent DOM object.

      Solution courtesy of: Elf Sternberg

      稿源:Node.js Recipes (源链) | 关于 | 阅读提示

      本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
      酷辣虫 » 前端开发 » nested template rendering in backbone.js

      喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录