Javascript 使用jQuery模板访问多维JSON ${Name} --选择一个${Name}-- ${$item.Options.Choice} 变量省份={ 名称:“省”, 选项:[ {值:“AB”,选项:“阿尔伯塔”}, {Value:“BC”,Choice:“不列颠哥伦比亚”}, {值:“MB”,选项:“马尼托巴省”}, {值:“NB”,选项:“新不伦瑞克”}, {值:“NF”,选项:“纽芬兰”}, {值:“NS”,选项:“新斯科舍省”}, {值:“NT”,选项:“西北地区”}, {值:“NU”,选项:“Nunavut”}, {Value:“ON”,Choice:“anthroa”}, {值:“PE”,选项:“爱德华王子岛”}, {值:“QC”,选项:“魁北克”}, {值:“SK”,选项:“萨斯喀彻温省”}, {值:“YT”,选项:“育空”} ] }; //使用省数据呈现模板并插入 //“movieList”元素下呈现的HTML $(“#dropdownTemplate”).tmpl(省)。附加到(“#movieList”);

Javascript 使用jQuery模板访问多维JSON ${Name} --选择一个${Name}-- ${$item.Options.Choice} 变量省份={ 名称:“省”, 选项:[ {值:“AB”,选项:“阿尔伯塔”}, {Value:“BC”,Choice:“不列颠哥伦比亚”}, {值:“MB”,选项:“马尼托巴省”}, {值:“NB”,选项:“新不伦瑞克”}, {值:“NF”,选项:“纽芬兰”}, {值:“NS”,选项:“新斯科舍省”}, {值:“NT”,选项:“西北地区”}, {值:“NU”,选项:“Nunavut”}, {Value:“ON”,Choice:“anthroa”}, {值:“PE”,选项:“爱德华王子岛”}, {值:“QC”,选项:“魁北克”}, {值:“SK”,选项:“萨斯喀彻温省”}, {值:“YT”,选项:“育空”} ] }; //使用省数据呈现模板并插入 //“movieList”元素下呈现的HTML $(“#dropdownTemplate”).tmpl(省)。附加到(“#movieList”);,javascript,jquery,jquery-templates,Javascript,Jquery,Jquery Templates,在我的jQuery模板中显示值或选项的正确语法是什么 1) 拆分下拉列表tempalte以选择标记模板和选项模板。 2) 使用嵌套模板选项填充下拉列表的选项。 3) 将省作为数组对象传递 以下是脚本更改: <script id="dropdownTemplate" type="text/x-jquery-tmpl"> <label for="${Name.toLowerCase()}">${Name}</label> <selec

在我的jQuery模板中显示
选项
的正确语法是什么 1) 拆分下拉列表tempalte以选择标记模板和选项模板。 2) 使用嵌套模板选项填充下拉列表的选项。 3) 将省作为数组对象传递

以下是脚本更改:

<script id="dropdownTemplate" type="text/x-jquery-tmpl">
    <label for="${Name.toLowerCase()}">${Name}</label>
        <select name="${Name.toLowerCase()}" id="${Name.toLowerCase()}_dropdown">
            <option selected='' value=''>-- Select a ${Name} --</option>
            <option value="${$item.Options.Value}">${$item.Options.Choice}</option> 
        </select>
</script>

    var provinces = {
        Name: "Province",
        Options: [
          { Value: "AB", Choice: "Alberta" },
          { Value: "BC", Choice: "British Columbia" },
          { Value: "MB", Choice: "Manitoba" },
          { Value: "NB", Choice: "New Brunswick" },
          { Value: "NF", Choice: "Newfoundland" },
          { Value: "NS", Choice: "Nova Scotia" },
          { Value: "NT", Choice: "Northwest Territories" },
          { Value: "NU", Choice: "Nunavut" },
          { Value: "ON", Choice: "Ontario" },
          { Value: "PE", Choice: "Prince Edward Island" },
          { Value: "QC", Choice: "Quebec" },
          { Value: "SK", Choice: "Saskatchewan" },
          { Value: "YT", Choice: "Yukon" }
        ]
    };


    // Render the template with the provinces data and insert
    // the rendered HTML under the "movieList" element
    $( "#dropdownTemplate" ).tmpl( provinces ).appendTo( "#movieList" );

${Name}
--选择一个${Name}--
{{tmpl(选项)“#optionTemplate”}
${Choice}
变量省份={
名称:“省”,
选项:[
{值:“AB”,选项:“阿尔伯塔”},
{Value:“BC”,Choice:“不列颠哥伦比亚”},
{值:“MB”,选项:“马尼托巴省”},
{值:“NB”,选项:“新不伦瑞克”},
{值:“NF”,选项:“纽芬兰”},
{值:“NS”,选项:“新斯科舍省”},
{值:“NT”,选项:“西北地区”},
{值:“NU”,选项:“Nunavut”},
{Value:“ON”,Choice:“anthroa”},
{值:“PE”,选项:“爱德华王子岛”},
{值:“QC”,选项:“魁北克”},
{值:“SK”,选项:“萨斯喀彻温省”},
{值:“YT”,选项:“育空”}
]
};
//使用省数据呈现模板并插入
//“movieList”元素下呈现的HTML
$(“#dropdownTemplate”).tmpl([省份])。附录(“#movieList”);
<script id="dropdownTemplate" type="text/x-jquery-tmpl">
    <label for="${Name.toLowerCase()}">${Name}</label>
        <select name="${Name.toLowerCase()}" id="${Name.toLowerCase()}_dropdown">
            <option selected='' value=''>-- Select a ${Name} --</option>
            {{tmpl(Options) "#optionTemplate"}}
        </select>
</script>

<script id="optionTemplate" type="text/x-jquery-tmpl">
    <option value="${Value}">${Choice}</option> 
</script>
<div id="movieList"></div>
<script>
var provinces = {
            Name: "Province",
            Options: [
              { Value: "AB", Choice: "Alberta" },
              { Value: "BC", Choice: "British Columbia" },
              { Value: "MB", Choice: "Manitoba" },
              { Value: "NB", Choice: "New Brunswick" },
              { Value: "NF", Choice: "Newfoundland" },
              { Value: "NS", Choice: "Nova Scotia" },
              { Value: "NT", Choice: "Northwest Territories" },
              { Value: "NU", Choice: "Nunavut" },
              { Value: "ON", Choice: "Ontario" },
              { Value: "PE", Choice: "Prince Edward Island" },
              { Value: "QC", Choice: "Quebec" },
              { Value: "SK", Choice: "Saskatchewan" },
              { Value: "YT", Choice: "Yukon" }
            ]
        };


        // Render the template with the provinces data and insert
        // the rendered HTML under the "movieList" element
        $( "#dropdownTemplate" ).tmpl( [provinces] ).appendTo( "#movieList" );
</script>