Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

knockout not evaluating expressions in IE7

When I run my program in Mozilla, it resolves the knockout expressions and shows the values in the observable array. When I do the same in IE7, it shows knockout code.

Mozilla results

value 1
value 2
value 3

IE7 results

function observable() { 
   if (arguments.length > 0) {
        // Write
        // Ignore writes if the value hasn't changed
        if ((!observable['equalityComparer']) || !observable['equalityComparer'](_latestValue, arguments[0])) {
            observable.valueWillMutate();
            _latestValue = arguments[0];
            if (DEBUG) observable._latestValue = _latestValue;
            observable.valueHasMutated();            
        }
        return this; // Permits chained assignments        
   }        
   else {
        // Read
        ko.dependencyDetection.registerDependency(observable); // The caller only needs to be notified of changes if they did a "read" operation
        return _latestValue;       
   }
}

How can I make this work correctly in IE7?

like image 763
user1813251 Avatar asked Nov 04 '22 09:11

user1813251


1 Answers

IE browsers do not support indexOf for an array, which arises issue with knockout.js framework.

Add the below javascript, it might resolve your issue:

    //
    // IE browsers do not support indexOf method for an Array. Hence 
    // we add it below after performing the check on the existence of
    // the same.
    //
    if (!Array.prototype.indexOf)
    {
        Array.prototype.indexOf = function (obj, start)
        {
            for (var i = (start || 0), j = this.length; i < j; i++)
            {
                if (this[i] === obj)
                {
                    return i;
                }
            }
            return -1;
        };
    }
like image 162
Rups Avatar answered Nov 09 '22 13:11

Rups