2

angular js で Ignite UI グリッド ディレクティブを使用しています。$.ig.EditorProvider その中で、HTMLマークアップでそのエディターを次のように拡張して使用することにより、カスタムエディタープロバイダーを作成しています

<column-setting column-key="comments" editor-provider="new $.ig.EditorProviderNumber()"> 
</column-setting>

しかし、グリッドを編集するとエラーが表示されます

provider.createEditor is not a function

助けてください

4

1 に答える 1

4

このように記述すると、「editor-provider」の値は文字列として評価されます。{{}}式をオブジェクトに解析するには、式を(二重中かっこ)で囲む必要があります。ただし、"new $.ig.EditorProviderNumber()" ステートメントはAngular 1 式パーサーによって解析されないため、スコープ関数を使用してオブジェクトを作成する必要があります。

コードは次のとおりです。

// This editor provider demonstrates how to wrap HTML 5 number INPUT into editor provider for the igGridUpdating
$.ig.EditorProviderNumber = $.ig.EditorProviderNumber || $.ig.EditorProvider.extend({
    // initialize the editor
    createEditor: function (callbacks, key, editorOptions, tabIndex, format, element) {
        element = element || $('<input type="number" />');
        /* call parent createEditor */
        this._super(callbacks, key, editorOptions, tabIndex, format, element);

        element.on("keydown", $.proxy(this.keyDown, this));
        element.on("change", $.proxy(this.change, this));
        this.editor = {};
        this.editor.element = element;
        return element;
    },
    keyDown: function(evt) {
        var ui = {};
        ui.owner = this.editor.element;
        ui.owner.element = this.editor.element;
        this.callbacks.keyDown(evt, ui, this.columnKey);
        // enable "Done" button only for numeric character
        if ((evt.keyCode >= 48 && evt.keyCode <= 57) || (evt.keyCode >= 96 && evt.keyCode <= 105)) {
            this.callbacks.textChanged(evt, ui, this.columnKey);
        }
    },
    change: function (evt) {
        var ui = {};
        ui.owner = this.editor.element;
        ui.owner.element = this.editor.element;
        this.callbacks.textChanged(evt, ui, this.columnKey);
    },
    // get editor value
    getValue: function () {
        return parseFloat(this.editor.element.val());
    },
    // set editor value
    setValue: function (val) {
        return this.editor.element.val(val || 0);
    },
    // size the editor into the TD cell
    setSize: function (width, height) {
      this.editor.element.css({
            width: width - 2,
            height: height - 2,
            borderWidth: "1px",
            backgroundPositionY: "9px"
      });
    },
    // attach for the error events
    attachErrorEvents: function (errorShowing, errorShown, errorHidden) {
        // implement error logic here
    },
    // focus the editor
    setFocus: function () {
        this.editor.element.select();
    },
    // validate the editor
    validator: function () {
        // no validator
        return null;
    },
    // destroy the editor
    destroy: function () {
        this.editor.remove();
    }
});

sampleApp.controller('sampleAppCtrl', function ($scope) {
    $scope.getProvider = function () {return new $.ig.EditorProviderNumber()};
});

<column-setting column-key="ProductNumber" editor-provider="{{getProvider()}}"></column-setting>
于 2016-07-22T13:36:03.197 に答える