我有 jqwidget 网格,用于管理名为“QuestionCategory”的实体;我有一个包含所有实体属性的 observableArray moduleQuestions 。当我想将从服务器获取的实体或从客户端新创建的实体推送到作为我的网格源的moduleQuestions中时,我确实有一个异常说TypeError: Converting circular structure to JSON。但是,当我删除实体的 entityAspect 时,我成功推送到我的 observableArray。这是添加新实体的方法。
createQuestionModule(data, observableModule: KnockoutObservableArray, moduleEntityAspect:KnockoutObservableArray){
//data object
//observableModule :moduleQuestions KnockoutObservableArray
//moduleEntityAspect an observableArray to keep track of each entity's entityAspect
var newQuestionModuleType :any= this.manager.metadataStore.getEntityType("QuestionCategory");
var newQuestionModule = newQuestionModuleType.createEntity(data);
var mapper = this.manager.addEntity(newQuestionModule);
moduleEntityAspect.push(mapper.entityAspect);//obervableArray to hold annoying entityAspect before deleting it
delete mapper.entityAspect;
observableModule.push(mapper);
observableModule.valueHasMutated();
}
所以我在将实体推送到我的 observableArray 之前删除了 entityAspect,并且我成功显示了一个网格。这是产生网格的淘汰赛绑定:
<div data-bind="jqxGrid: {
source: moduleQuestions,
autoheight: true,
//rendertoolbar : '',
theme: 'bootstrap',
editable: true,
selectionmode: 'singlecell',
altrows:true,
sortable: true,
enabletooltips:true,
pageable: true,
autoheight: true,
showemptyrow: false,
autosavestate:true,
columns: [
{ text: 'Module Name', dataField: 'CategoryName', width: 100, cellsalign:'center', validation: moduleNameValidation, cellendedit:celledited },
{ text: 'Description', dataField: 'Description', width: 200, cellsalign: 'center', cellendedit: celledited },
{ text: 'Status', dataField: 'IsEnable', width: 100, columntype: 'checkbox', cellsalign: 'center', cellendedit: celledited },
{ text: 'Action', dataField: 'QuestionCategoryID', cellsrenderer: AddSubjectRender, editable: false, cellsalign: 'center', cellendedit: celledited }
]}" id="questionModuleGrid">
列数组中有一个cellendit调用特定函数celledited,每当编辑网格中的任何单元格时,都会在调用期间将五个参数传递给它。每当更新网格中的单元格时,就会发生这种情况。这是celledited函数:
celledited = (row, datafield, columntype, oldvalue, newvalue) => {
//row is the row index
//datafield is an entity property from breeze
// columntype is a type of column which can be checkbox,textbox etc
//oldvalue is the original value before being changed
//newvalue is the _latestValue
if (oldvalue != newvalue) {
var breezeEntityinGrid = QuestionCategory.moduleQuestions()[row];// this gives us the whole row that is being edited form observableArray =>moduleQuestions
var entityAspect = QuestionCategory.moduleEntityAspect()[row];// get the entityAspect of the enity.
breezeEntityinGrid["entityAspect"] = entityAspect; // to add the entityAspect back to the entity
//then, this produces exception when updating the particular entity property ()=>TypeError: Converting circular structure to JSON
breezeEntityinGrid[datafield](newvalue); //so i commented this out then, try the following method
breezeEntityinGrid.Description._latestValue = newvalue; //the property to be updated
var newQuestionModuleType = this.manager.metadataStore.getEntityType("QuestionCategory");
this.manager.attachEntity(breezeEntityinGrid, breeze.EntityState.Modified);//yet the manager is not aware of that
delete breezeEntityinGrid["entityAspect"];//to remove it from the entity
return true;
}
}
我很困惑。我想使用网格并在实体发生更改时设置它们的属性,以便在调用 saveChages 时可以保存更新的值,但是将其提交给微风管理器,就会出现问题。我需要帮助。