【问题标题】:Uncaught TypeError: this.firstname is not a function未捕获的类型错误:this.firstname 不是函数
【发布时间】:2021-12-15 10:31:57
【问题描述】:

我正在研究淘汰赛js并发生错误 有什么问题??

<span data-bind="text: fullname"></span>

<script type="text/javascript">
function AppViewModel() {
  this.firstName = ko.observable('Bob');
  this.lastName = ko.observable('Smith');

  this.fullname = ko.computed(function() {
    return this.firstname() + " " + this.lastname();
  },this);
}

// <!-- ko.applyBindings(viewModel); -->
var vm = new AppViewModel();
ko.applyBindings(vm);
</script>

当我调用这个时,

Uncaught TypeError: this.firstname is not a function

发生... 怎么了?

【问题讨论】:

  • 查看大小写...this.firstName = ...return this.firstname() + ...。您的this.lastName/this.lastname 变量也存在此问题

标签: javascript knockout.js


【解决方案1】:

return this.firstname() + " " + this.lastname();

firstnamelastname 中的“n”没有大写。所以尝试这样的事情:

function AppViewModel() {
  this.firstName = ko.observable('Bob');
  this.lastName = ko.observable('Smith');

  this.fullname = ko.computed(function() {
    return this.firstName() + " " + this.lastName();
  },this);
}

// <!-- ko.applyBindings(viewModel); -->
var vm = new AppViewModel();
ko.applyBindings(vm);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-19
    • 1970-01-01
    • 2019-06-06
    • 2019-05-24
    • 2019-10-26
    • 2016-06-27
    • 2021-12-19
    相关资源
    最近更新 更多