无法更新Azure门户扩展中的可编辑网格

时间:2016-07-09 15:58:22

标签: javascript azure typescript azureportal

我正在开发一个包含可编辑网格刀片的Azure 门户网站扩展。 网格刀片从选择器打开,因此包含参数提供程序

网格使用参数提供程序的编辑范围进行初始化,这是一个可观察的数组,已启用行编辑和插入新行

当我尝试更新网格时,对现有行的更改未显示,并且创建新行会产生空行,如下所示:

Empty line when adding new row

调试时我没有在控制台中看到任何错误。

这是我如何初始化网格:

private _initialize(container: MsPortalFx.ViewModels.PartContainerContract): void {
    var extensions: number = MsPortalFx.ViewModels.Controls.Lists.Grid.Extensions.EditableRow | MsPortalFx.ViewModels.Controls.Lists.Grid.Extensions.ContextMenuShortcut,
        extensionsOptions: MsPortalFx.ViewModels.Controls.Lists.Grid.ExtensionsOptions<DataModels.IItem, DataModels.ISelectionItem>,
        viewModel: MsPortalFx.ViewModels.Controls.Lists.Grid.ViewModel<DataModels.IItem, DataModels.ISelectionItem>;

    // Set up the editable extension options.
    extensionsOptions = this._createExtensionsOptions();

    // Create the grid view model.
    viewModel = new MsPortalFx.ViewModels.Controls.Lists.Grid.ViewModel<DataModels.IItem, DataModels.ISelectionItem>(
        container,
        null,
        extensions,
        extensionsOptions);
    viewModel.showHeader = true;
    viewModel.columns(this._columns);
    viewModel.rowAdd = () => {
        // code that extension authors need to execute when a row is added should go here.
    };
    this.editableGrid = viewModel;
}

private _createExtensionsOptions(): MsPortalFx.ViewModels.Controls.Lists.Grid.ExtensionsOptions<DataModels.IItem, DataModels.ISelectionItem> {
    return <MsPortalFx.ViewModels.Controls.Lists.Grid.ExtensionsOptions<DataModels.IItem, DataModels.ISelectionItem>>{
        editableRow: {
            // Supplies editable items to the grid.
            editScope: this.parameterProvider.editScope,
            // put the new row at the top.
            placement: MsPortalFx.ViewModels.Controls.Lists.Grid.EditableRowPlacement.Bottom,
            // Create no more than 5 new rows.
            maxBufferedRows: 5,
            // Allow the modification of existing items.
            allowEditExistingItems: true,
            // Allow the creation of new items.
            allowEditCreatedItems: true,
            // Track the valid status
            valid: ko.observable<boolean>()
        }
    };
}

我已经审核了几个可编辑网格样本刀片,但无法确定我做错了什么。

1 个答案:

答案 0 :(得分:0)

问题是我没有设置参数提供程序的 editScopeMetadataType 属性,这是确定编辑范围的实体类型所必需的:

this.parameterProvider = new MsPortalFx.ViewModels.ParameterProvider<DataModels.IItem[], KnockoutObservableArray<DataModels.SchemaItem>>(container, {

    // This was missing.
    editScopeMetadataType: wrapperTypeMetadataName,

    mapIncomingDataForEditScope: (incoming) => {
        return ko.observableArray(incoming);
    },

    mapOutgoingDataForCollector: (outgoing) => {
        return outgoing();
    }
});