未捕获的ReferenceError:无法处理绑定" foreach:function(){return milestonetListing.items}"消息:未定义milestonetListing

时间:2015-12-17 16:29:28

标签: knockout.js typescript asp.net-mvc-5.1

我是淘汰赛和打字稿的新手。我正在使用knockout在typescript中创建简单的类。但是当我运行它时,它向我展示了所有未定义的功能。我可能会错过一些参考资料。

输入脚本+淘汰赛

module App {
  class MilestoneSummary {
    constructor(summary ? : any) {
      if (summary) {
        this.id = summary.id;
        this.milestoneName = summary.milestoneName;
        this.milestoneDescription = summary.milestoneDescription;
      }
    }

    id: number;
    milestoneName: string;
    milestoneDescription: string;
  }
  export class Milestone {
    constructor(private _appointmentReference: string) {
      super();
      this.loadMilstones();
    }
    milestone = ko.observable < MilestoneSummary > ();
    milestonetListing = new Listing();

    loadMilstones() {
      if (this.isLoading.peek()) {
        return;
      }
      this.isLoading(true);
      var url = App.getApiUrl("Milestone", "Get", App.viewData.appointment.reference);

      Ajax.load(url)
        .done((data) => {
          var milestones = ko.utils.arrayMap(data, (dis) => {
            return new MilestoneSummary(dis);
          });

          this.milestonetListing.items(milestones);
        })
        .always(() => {
          this.isLoading(false);
        });
    }
  }

  var viewModel = new Milestone(App.viewData.appointment.reference);
  App.setViewModel(viewModel);
}

HTML代码

<tbody class="no-wrap" data-bind="foreach: milestonetListing.items, select: milestonetListing">
  <tr>
    <td data-bind="text: milestoneName"></td>
  </tr>
</tbody>

它总是给我错误里程碑列表没有定义。我尝试添加一个我创建的简单函数来显示弹出窗口并将其绑定到绑定。它还显示为未定义的函数。

我错过任何Ko参考吗?

0 个答案:

没有答案