self.save_form = function (data, event) {
if (event != undefined && event.srcElement != undefined && event.srcElement.classList != undefined && event.srcElement.classList.contains("save_form")) {
var processData = false;
var contentType = "application/json; charset=utf-8";
var stringify = true;
var unmapped = ko.mapping.toJS(autoDeployViewModel); //Invalid State Error
}
当在上面的live中取消映射viewModel时,只要我的IntakeForm可观察数组被填充,我就会得到一个InvalidStateError。
我已经缩小到每当我的IntakeForm对象被填充时:
AutoDeployFormViewModel = function () {
//Intake Form View Model
var self = this;
self.File = {};
self.XPathCollection = ko.observableArray([new XPathConfig()]);
self.IntakeForm = ko.observableArray([new IntakeFormData("Upload your web config.")]);
}
只要调用这些事件,就会完全填充IntakeForm对象:
whereAttrSelected: function (data, event) {
//alert("where selected");
if (event.srcElement.classList.contains("whereAttrSelected")) {
data.XPathConfig._selectedWhereClauseAttribute("[@" + data.Attribute + "=" + '"' + data.Value + '"' + ']');
data.XPathConfig._radioButtonWhere(event.srcElement); //store reference to rbtn that was clicked
}
return true;
},
transformAttrSelected: function (data, event) {
if (event.srcElement.classList.contains("transformAttrSelected")) {
data.XPathConfig._radioButtonTransform(event.srcElement); //store reference to rbtn that was clicked
data.XPathConfig._selectedTransformAttribute(data.Attribute);
var intakeFormData = autoDeployViewModel().IntakeForm();
var xPath = attr._fullXPath + data.XPathConfig._selectedWhereClauseAttribute() + '/' + "@" + data.XPathConfig._selectedTransformAttribute(); // XPATH STRING MANIPULATION
var updatedIntakeFormData = [];
updatedIntakeFormData.push(new IntakeFormData(xPath, attr)); //push most recent addition
//push the rest of the observable array
for (var i = 0; i < intakeFormData.length; i++) {
updatedIntakeFormData.push(new IntakeFormData(intakeFormData[i].Intake, intakeFormData[i].Attribute))
}
autoDeployViewModel().update_intake_form(updatedIntakeFormData);//update ui by replacing XPaths
}
return true;
}
基本上XPathConfig点击事件允许我将一些字符串数据和对所选单选按钮的引用存储到一个observable中。问题是,当我准备转换为javascript对象时,当我尝试取消映射时,会发生无效状态错误。
data.XPathConfig._selectedWhereClauseAttribute("[@" + data.Attribute + "=" + '"' + data.Value + '"' + ']');
data.XPathConfig._radioButtonWhere(event.srcElement); //store reference to rbtn that was clicked
data.XPathConfig._radioButtonTransform(event.srcElement); //store reference to rbtn that was clicked
data.XPathConfig._selectedTransformAttribute(data.Attribute);
如果设置了上述可观察对象,有人可以解释为什么在取消映射viewModel时状态可能无效吗?