0
나는 결과에 따라 확인 될 때마다 체크 상자를 선택 해제하려면 노력하고 있어요,하지만 난 부울라는 오류가선택 취소 확인란은
function IndexVM() {
// Observable objects
this.Files = ko.observableArray([]);
this.CreateAML = function() {
var self = this;
for (var i = 0; i < self.Files().length; i++) {
if (self.Files()[i].Selected) {
$.ajax({
type: "POST",
url: "Home/CreateAML",
dataType: 'json',
data: "{ 'File': " + ko.toJSON(self.Files()[i]) + "}",
contentType: "application/json",
success: function (response) {
self.Files()[i].Selected(response.d); //this is where the error is thrown
}
}
};
};
뷰 모델
기능
아니다
업데이트 :
function File() {
var self = this;
self.Selected = ko.observable(false);
// ...more properties
};
function IndexVM() {
var self = this;
// Observable objects
self.Path = ko.observable();
self.Files = ko.observableArray([]);
self.selectedFiles = ko.computed(function() {
return ko.utils.arrayFilter(self.Files(), function (file) {
return file.Selected();
});
});
this.CreateAML = function() {
var self = this;
ko.utils.arrayForEach(self.selectedFiles(), function (file) {
$.ajax({
url: "Home/CreateAMLTest",
contentType: "application/json; charset=utf-8",
data: ko.toJSON({
File: ko.toJS(file)
})
}).done(function (response) {
file.Selected(response.d);
}).fail(function (jqXHR, textStatus, errorThrown) {
// handle the error
});
});
};
};
감사합니다. 감사합니다. this.selectedFiles = ko.pureComputed (function() { – Gericke
어떤 버전의 knockout을 사용하고 있습니까? 3.2보다 작 으면'computed()'를 사용하십시오. [순수 계산] (http://knockoutjs.com/documentation/computed-pure.html)이 3.2에서 소개되었으므로 사용할 수 없다면 정상적인 것을 염두에 두지 마십시오. – Tomalak
나는 3.0을 사용하고 있기 때문에 나의 이해는 잘 돌아 간다. – Gericke