我不断收到错误:未捕获的TypeError:无法读取未定义的属性'fromJS'
这个想法是有2个页面,其中ui表示形式,另一个是het viewmodel。
我有2页:

Index.html

<link rel="stylesheet" href="bin/styles/kendo.common.min.css" />
<link rel="stylesheet" href="bin/styles/kendo.default.min.css" />
<link rel="stylesheet" href="bin/styles/kendo.dataviz.min.css" />
<link rel="stylesheet" href="bin/styles/kendo.dataviz.default.min.css" />

<script src="bin/js/jquery.min.js"></script>
<script src="bin/js/kendo.all.min.js"></script>
<script src="bin/knockout-3.2.0.js"></script>
<script src="bin/knockout.mapping-latest.js" type="text/html"></script>

<script src="IndexViewModel.js"></script>

<script>
    $(function() {
        var indexVM = new IndexViewModel.ViewModel();
        ko.applyBindings(indexVM);
    });
</script>


<table>
    <thead><tr>
        <th>First Name</th>
    </tr></thead>
    <tbody data-bind="foreach: Users">
        <tr>
            <td data-bind="text: UserName"/></td>
        </tr>
    </tbody>
</table>


和IndexViewModel.js:

var IndexViewModel = (function (IndexViewModel) {
IndexViewModel.ViewModel = function() {
    var self = this;
    self.Users = ko.observableArray();
    $.ajax({
        url : 'GetUsers.php',
        dataType: 'json',
        success: function(data){ //json string of the student records returned from the server
        self.Users = ko.mapping.fromJS(result.data, {}, self.Users);
        }
    });
}
    return IndexViewModel;
}(IndexViewModel || {}));


我在做什么错/想念?

谢谢

最佳答案

解决了这个问题。问题是

<script src="bin/knockout.mapping-latest.js" type="text/html"></script>


变成 :

<script src="bin/knockout.mapping-latest.js"></script>


起飞:type =“ text / html”

关于javascript - 无法读取外部viewmodel.js中未定义的属性“fromJS”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28342211/

10-09 01:14