2013-03-18 54 views
2

多個值,我使用jQuery的模板來渲染頁面,在這裏我使用的模板組合遍歷並顯示一個頁面。傳遞和訪問jQuery的模板,模板組合

{{if simulateBomPageData.groupNames}} 
    {{each simulateBomPageData.groupNames}} 
    {{tmpl($value,simulateBomPageData.materialData.characterAttributesData.attributeMap[$value],$index) "#characters_group"}} 
    {{/each}} 
{{/if}} 

我的子模板看起來如下

<script id="characters_group" type="text/x-jQuery-tmpl"> 
    {{=$index}}" {{=$value}}(Value from fro each loop) 
the entry in the map 
and the {{=$index}} 
    </script> 

請讓我知道如何訪問和傳遞這些價值

回答

1

,我發現自己的答案如下

function My_Class(name,object1,object2) 
{ 
    this.name=name; 
    this.object1=object1; 
    this.object2=object2; 
} 

要值傳遞給模板

{{tmpl(new My_Class("Name",obj1,obj2)) "#characters_group"}} 

而且你可以如下訪問模板中的值

<script id="characters_group" type="text/x-jQuery-tmpl"> 
    Name: {{= name}} 
    Object1: {{= object1}} 
    Object2: {{= object2}} 
</script>