Есть две функции, объявленные одинаково. В зависимости от возвращаемого результата этих функций элементы на страницы должны появляться/скрываться. Одна работает, вторая тоже, но не динамически.
function PassportViewModel() {
var self = this;
var foreignDocumentTypeList = " + @Html.Raw(Json.Encode(ViewBag.ForeighDocumentTypeList as int[])) + @";
self.chosenIdentificationDoctype = ko.observable();
self.isForeign = ko.computed(function() {
return foreignDocumentTypeList.indexOf(parseInt(self.chosenIdentificationDoctype())) > -1;
});
self.isForeignCit = ko.computed(function() {
return ($('#IdentificationDoctype_Id').val() == 20);
});
};
<div class="col-md-2">
<label data-bind="text:isForeign()?'Тип':'Серия'"></label>
</div>
<div class="col-md-2">
@Html.TextBoxFor(m => m.PassportSerial, new { @class = "form-control" }) @Html.ValidationMessageFor(m => m.PassportSerial)
</div>
<div class="col-md-2" data-bind="style:{display:isForeignCit()?'block':'none'}">
@Html.LabelFor(m => m.Belonging)
</div>
<div class="col-md-3" data-bind="style:{display:isForeignCit()?'block':'none'}">
@Html.HiddenFor(m => m.Belonging.Id, new { @class = "form-control", @style = "border:0;padding:0;margin:0;" }) @Html.ValidationMessageFor(m => m.Belonging)
</div>
Сборка персонального компьютера от Artline: умный выбор для современных пользователей