gpt4 book ai didi

javascript - Knockout JS 中的 validateObservable - undefined 不是函数

转载 作者:行者123 更新时间:2023-11-29 19:33:53 25 4
gpt4 key购买 nike

你好,

我正在尝试验证我这边的一个非常大的表单,并且基本上重写了我所有的 viewModel 代码以便可以对其进行验证。问题是 ko.validatedObservable() 由于某种原因似乎不存在。我使用了 this site 的代码,老实说,我看不出我的代码有什么问题。这是一个示例:

var someNameSpace= {};

someNameSpace.bindData = function () {
someNameSpace.viewModel =
someNameSpace.initViewModel("123456", "username1", "address1", "address2", "city");

ko.applyBindings(this.viewModel);
}

someNameSpace.initViewModel = function (partnerId, username, address1, address2, city) {
console.log(ko);
var someViewModel = ko.validatedObservable({ //<----FAILS HERE
partnerId: ko.observable(partnerId).extend({ required: "This field is required", number: true }),
username: ko.observable(username).extend({ required: "This field is required" }),
address1: ko.observable(address1).extend({ required: "This field is required" }),
address2: ko.observable(address2).extend({ required: "This field is required" }),
city: ko.observable(city).extend({ required: "This field is required" }),
});

var validationOptions = { insertMessages: true, decorateElement: true };
ko.validation.init(validationOptions);

return someViewModel ;
}

$(document).ready(function () {
someNamespace.bindData();
});

在该站点上,它声称使用 ko.validatedObservable 来检查用户是否正确输入了字段。我对 knockoutJS 还是很陌生 - 我能做什么?

error

最佳答案

您需要包含对 'knockout.validation.js' 库的引用。

knockout.validation.js

https://rawgit.com/ericmbarnard/Knockout-Validation/master/Src/knockout.validation.js

GitHub 引用

https://github.com/Knockout-Contrib/Knockout-Validation

关于javascript - Knockout JS 中的 validateObservable - undefined 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26039075/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com