Skip to content

TypeError: viewModelObj is not a function #66

@DjCzermino

Description

@DjCzermino

We have a problem on line 412 in latest knockout.viewmodel.2.0.3.js (tested also in previous version - same problem).

If viewmodel and model contains array deep in their structure, line 415 fires error when we call ko.viewmodel.updateFromModel function:

TypeError: viewModelObj is not a function

Code on this error:
"viewModelObj(tempArray);" -- here is viewModelObj classic JS array, not observ. function...

I temporarily solved by modifying the source code as follows:

Original code:
...
else {//Can't use indexer for assignment; have to preserve original mapping with push
viewModelObj(tempArray);
for (p = 0, length = modelObj ? modelObj.length : 0; p < length; p++) {
viewModelObj.pushFromModel(modelObj[p]);
}
}
...
New temporary code:
...
else {//Can't use indexer for assignment; have to preserve original mapping with push
if (viewModelObj instanceof Array) {
if (JSON.stringify(viewModelObj) != JSON.stringify(modelObj)) {
// TODO: update viewModelObj array by modelObj
...
}
} else {
viewModelObj(tempArray);
for (p = 0, length = modelObj ? modelObj.length : 0; p < length; p++) {
viewModelObj.pushFromModel(modelObj[p]);
}
}
}
...

Does anyone have the same problem? Maybe we have bad input data, bud with previous ko.mapping plugin updating model with same structure worked well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions