Knockout.js显示可观察对象

时间:2018-05-22 13:57:27

标签: javascript razor knockout.js observable

我有一个Ticket observable模型,其中包含User可观察模型,我想显示User-> Firstname和 - > Lastname字段。 Firstname字段显示正确,但在我收到错误后。

HTML

h5

错误

.row {
  display: flex;
  align-items: center;
}

#row1 select {
  flex-grow: 2;
}

#row1 h5 {
  flex-grow: 1;
}

#row2 select {
  flex-grow: 1;
}

的ViewModels

LiveTicket

<div class="row" id="row1">
  <select>
    <option>Choose</option>
    <option>Option 1</option>
    <option>Option 2</option>
  </select>
  <h5>A question</h5>
</div>
<div class="row" id="row2">
  <select>
    <option>Choose the correct answer</option>
    <option>Option 1</option>
    <option>Option 2</option>
  </select>
</div>

的usermodel

<span data-bind="text: manageLiveTicket.CardID"></span>
<span data-bind="text: manageLiveTicket.UserID"></span>
<span data-bind="text: manageLiveTicket.User().FirstName"></span>

0 个答案:

没有答案