1

jQuery handontable プラグインを使用していますが、「依存」列を使用する方法があるかどうか疑問に思っています。

これは、1 つの列を変更すると、前の列の値に応じてもう 1 つの列が更新されるということです。

私の列の 1 つは calllocationで、オートコンプリートには可能な場所のリストが表示されます。(市区町村 + 郵便番号 + 国) その通りですが、私のデータベースでは、id場所ごとに のみを保存しています。locationそのため、それを保存するための非表示の列が必要です(既に作成しています)が、ユーザーがオートコンプリートを使用して列を変更したときに更新する必要があります。

それはどういうわけか可能ですか?ドキュメントでもインターネットでも何も見つかりませんでした。

ありがとう。

4

1 に答える 1

1

はい、私はあなたと同じ理由でこれを行いました

afterChange イベントを使用して...

afterChange: function (changes, source) { AfterChange(changes, source); }

...他のセルの値を変更できます...

function AfterChange(Changes, Source) {
    if (Source === 'loadData') {
        return; //don't do anything on load
    }
    var rowIndex = 0, columnID = 1, oldTextVal = 2, newTextVal = 3, ntv = '', nv = '';
    $(Changes).each(function () {
        if (this[columnID] === 'RegionID') {
            //Make sure nothing else happens when these columns are set through below, to avoid circular references
        }
        else if (this[columnID] === 'RegionName') {
            ntv = this[newTextVal];
            //I have a dropdown used for filtering which has the id as value where I get the id from
            nv = $('#RegionsFilterDropdown option').filter(function () { return $(this).text() === ntv; }).val();
            $container.handsontable('setDataAtCell', this[rowIndex], 12, nv);
        }
    });
}

これが役立つことを願っています...

于 2013-06-27T23:09:21.240 に答える