挖空值绑定未处理



我目前正在尝试通过 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

我试图找到解决方案,但失败了。

有人对我可能做错了什么有任何想法吗?

是由

一个苗条版本的jQuery引起的。完整版正在使用中,并且一切正常。

相关内容

最新更新