Мне нужно отключить конкретное текстовое поле из списка динамически созданных текстовых полей. Рассмотрим код, в котором я динамически создаю 5 текстовых полей с помощью «кнопки создания», из которого мне нужно отключить 2-е текстовое поле.
<input type="button" value="Create TextBox" data-bind="click: addCourse"/>
<input type="button" value="Disable 2nd TextBox" data-bind="click: disable"/>
<div data-bind="foreach: cources">
<div>
<input type="text" data-bind="value: textValue,disable: disableStatus"/>
</div>
</div>
<div data-bind="foreach: cources">
<div>
<span type="text" data-bind="text: textValue"/>
</div>
</div>
js-код:
function CourseViewModel(){
this.textValue = ko.observable('');
this.disableStatus = ko.observable(false);
}
function CeremonyViewModel() {
this.cources = ko.observableArray();
this.addCourse = function(){
this.cources.push(new CourseViewModel());
};
this.disable = function()
{
this.disableStatus(true);
}
}
ko.applyBindings(new CeremonyViewModel());