Internet Explorer 中 jQuery 模板的 {{each}} 标记存在错误行为?
我正在使用 jQuery 模板构建页面,但在 IE 8 中出现一些不一致的行为。
我在 {{each}} 标记内有一个复选框元素,但当我尝试将字符串附加到 id 时,IE 会抛出错误。
这是 HTML 片段:
<script id="filters-template" type="text/template">
<div id="CoinsuranceFilters" class="filters">
<h4><label><input type="checkbox" id="checkall_coinsurance" onclick="checkClass(this, 'coinsurance_items');" class="checkall" /> Coinsurance</label></h4>
{{each Coinsurance}}
<div class="filteritem">
<label><input type="checkbox" id="${'Coinsurance_' + id}" {{if IsSelected}} checked{{/if}} class="coinsurance_items"/> ${ItemText}</label>
</div>
{{/each}}
</div>
</script>
IE reports: 'id' is undefined
如果我将 id 字段更改为 id="${id}" ,错误就会消失(尽管它似乎为每 1 个复选框呈现 2 个复选框)。
这在 Chrome 和 FF 4 中没有任何问题
此页面使用 jquery 1.5.2 & jquery-ui 1.8.12
这是传递到模板中的 JSON 对象:
{
"IndividualQuoteID": "539b9d05-0c78-4c27-b238-9edaaabfb389",
"Coinsurance": [
{
"id": 267,
"ID": 267,
"IsSelected": true,
"ItemText": "70%"
},
{
"id": 266,
"ID": 266,
"IsSelected": true,
"ItemText": "80%"
},
{
"id": 265,
"ID": 265,
"IsSelected": true,
"ItemText": "90%"
},
{
"id": 264,
"ID": 264,
"IsSelected": true,
"ItemText": "100%"
}
]
}
(id 和 ID 值是故意存在的。我尝试与 {{each}} 块内的字符串连接的任何键都会发生此错误)
I am building a page using jQuery templates, but getting some inconsistent behavior in IE 8.
I have a checkbox element inside an {{each}} tag, but IE throws an error when I try to append a string to the id.
Here is the HTML fragment:
<script id="filters-template" type="text/template">
<div id="CoinsuranceFilters" class="filters">
<h4><label><input type="checkbox" id="checkall_coinsurance" onclick="checkClass(this, 'coinsurance_items');" class="checkall" /> Coinsurance</label></h4>
{{each Coinsurance}}
<div class="filteritem">
<label><input type="checkbox" id="${'Coinsurance_' + id}" {{if IsSelected}} checked{{/if}} class="coinsurance_items"/> ${ItemText}</label>
</div>
{{/each}}
</div>
</script>
IE reports: 'id' is undefined
If I change the id field to id="${id}" the error goes away (although it appears to render 2 checkboxes for every 1 it should).
This works with no problems in Chrome and FF 4
This page uses jquery 1.5.2 & jquery-ui 1.8.12
Here is the JSON object that gets passed into the template:
{
"IndividualQuoteID": "539b9d05-0c78-4c27-b238-9edaaabfb389",
"Coinsurance": [
{
"id": 267,
"ID": 267,
"IsSelected": true,
"ItemText": "70%"
},
{
"id": 266,
"ID": 266,
"IsSelected": true,
"ItemText": "80%"
},
{
"id": 265,
"ID": 265,
"IsSelected": true,
"ItemText": "90%"
},
{
"id": 264,
"ID": 264,
"IsSelected": true,
"ItemText": "100%"
}
]
}
(The id and ID values are there intentionally. This error occurs with any key I try to concatenate with a string inside the {{each}} block)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我从未使用过 Jquery 模板,但从我在代码中看到的内容来看,它不应该是这样的:
我不明白 ${'Coinsurance_' + id} 语法指的是什么。如果我没猜错的话,您希望复选框的 html id 为“Coinsurance_267”。
I never used Jquery templates, but from what I see in your code shouldn't it be like this :
I don't see what the ${'Coinsurance_' + id} syntax would refer to. If i get it right you want the checkbox to have the html id 'Coinsurance_267'.