我目前正在尝试通过Knockout使用与select
元素绑定的值。我也在文档上使用Boostrap V4(过去我遇到了两个问题)。
select
的html如下:
<select id="opsGroup" class="custom-select" data-bind="options: opsGroups,
optionsCaption: 'Please select...',
value: selectedOpsGroup">
</select>
相关的Javascript如下:
function ViewModelTemplate(opsGroups, branchInfo) {
var self = this;
self.opsGroups = ko.observableArray(opsGroups);
self.branchesByGroup = ko.observable(branchInfo);
self.selectedOpsGroup = ko.observable();
self.selectedBranch = ko.observable();
self.branchesForGroup = ko.computed(function() {
return self.branchesByGroup()[self.selectedOpsGroup()] || [];
});
}
function loadBranchInfo(e) {
var viewModel = new ViewModelTemplate(e.opsGroups, e.branchInfo);
ko.applyBindings(viewModel);
}
opsGroups
只是一个字符串数组。
每当我尝试运行时,我都会收到消息:
Uncaught TypeError: Unable to process binding "value: function (){return selectedOpsGroup }"
Message: u(...).bind is not a function
我已经尝试过找到解决方案,但失败了。
任何人对我可能做错了什么都有任何想法?
答案 0 :(得分:0)
是由简洁的jQuery版本引起的。 正在使用的完整版本,所有功能都正常。