我有一个Users表,每个用户都可点击,一旦你点击它 - 一个带有用户信息的模态弹出窗口。
模态的export class CandidateVerificationComponent implements OnChanges, OnInit {
@ViewChild(RightPanelComponent) rightPanelPointer: RightPanelComponent;
saveAndFinish() {
if (this.rightPanelPointer.form.valid)
:
div
问题是如果<div class="infoForm" data-bind="with: $root.selectedItem">
<input id="companyName" placeholder="Company Name" data-bind="value: name" />
<div class="cont">
<label for="address">ADDRESS</label>
<input class="contField" placeholder="Address 1" id="address" data-bind="value: address1" />
<input class="contField" placeholder="Address 2" id="address2" data-bind="value: address2" />
<input class="contField" id="city" placeholder="City" data-bind="value: city" />
<input class="contField" id="state" placeholder="State" data-bind="value: state" />
<input class="contField" id="zip" placeholder="Zip" data-bind="value: zip" />
...
</div>
为空,则模态弹出空白,没有任何内容。
我希望仅在selectedItem
不是data-bind
的情况下才会向$root.selectedItem
添加一个条件,因为当我取出它null
时它会起作用。< / p>
我试过了:
data-bind
但它不起作用,只是不会发生,在其他类型的绑定中(<div class="infoForm" data-bind="with: $root.selectedItem ? $root.selectedItem : ''">
.....
</div>
,text
确实有效)。
当点击桌面上的其中一个用户时,正在设置value
:
selectedItem
视图模型:
<td class="name n" data-bind="text: name, click: $root.setSelectedItems.bind($data)"></td>
关于如何实现这一点的任何想法?
答案 0 :(得分:1)
我通过将selectedItem
设置为空user
来解决此问题:
self.selectedItem = ko.observable(new User(""));