最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - IE versions earlier than 9 raises error "Expected identifier, string or number” - Stack Overflow

programmeradmin1浏览0评论

This knockout 2.1 binding expression works fine under Firefox and IE9, but crashes in IE9 patibility mode with error "Expected identifier, string or number”:

<div data-bind="template: {
    if: myDataModel, 
    data: myDataModel, 
    afterRender: setup(myDataModel) }">

I found actual place under debugger, it's this line of code (knockout-2.1.0.debug.js):

return new Function("sc", functionBody)

functionBody is a string equal to the expression above. I tried to play with spaces and carriage return characters - nothing helps, same results: it works as expected with any browser other than IE9 patibility mode

Any suggestions?

This knockout 2.1 binding expression works fine under Firefox and IE9, but crashes in IE9 patibility mode with error "Expected identifier, string or number”:

<div data-bind="template: {
    if: myDataModel, 
    data: myDataModel, 
    afterRender: setup(myDataModel) }">

I found actual place under debugger, it's this line of code (knockout-2.1.0.debug.js):

return new Function("sc", functionBody)

functionBody is a string equal to the expression above. I tried to play with spaces and carriage return characters - nothing helps, same results: it works as expected with any browser other than IE9 patibility mode

Any suggestions?

Share Improve this question asked Oct 26, 2012 at 16:21 YMCYMC 5,4629 gold badges64 silver badges99 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 12

I think the issue is that older versions of IE don't like "if" or similar reserved words to appear as property names. Try putting single quotes around the property names.

<div data-bind="template: {
'if': myDataModel, 
data: myDataModel, 
afterRender: setup(myDataModel) }">

Another mon time that you'll have this happen when you have a "class" binding. Same fix:

<tr data-bind="attr: { 'class': packageSelected() ? 'success' : '' }">

List of reserved words in JS: https://developer.mozilla/en-US/docs/JavaScript/Reference/Reserved_Words

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论