1

こんにちは、注文の配列を取り、配列内の各注文の行を作成する JQuery プラグインがあります。ここでは問題ありません。ただし、これらの注文の 1 つが条件を満たす場合、TD セルの 1 つにテキストボックスを追加する必要があります。デバッグすると、テキストボックスが追加されているのがわかりますが、テキストボックスを必要とする次の行が作成されると、前のテキストボックスが削除されます。私はこれをクローズ内に持っているので、どうすればよいかわかりません。その結果、最後の行にのみテキストボックスが表示されます。

textBox を html として追加すると問題なく動作しますが、いくつかのイベント KeyUp/Down MouseWheel、Click をバインドする必要があるため、プラグインとして使用したいと考えています。など テキスト ボックス プラグイン コントロール (gep_inputcontrol) は、html を作成してイベントをバインドするだけで、特別なことは何もありません。

どんな助けでも感謝します。


var _table = $('#orderTable', this);
for (var i = 0; i < params.orders.length; i++) {
    var row = createRow(params.orders[i]);
    _table.append(row);
}

function createRow(order){
    var unmatchedStake = (order.requestedStake - order.matchedStake);
    var partMatched = (unmatchedStake > 0);


    var tr = $(String.format('<tr id="order_{0}" class="{1}"/>' ,order.orderId, ((i % 2) == 0) ? 'gep-altrow' : 'gep-row'));

            tr.append(String.format('<td class="gep-icon gep-status">{0}</td>', order.orderStatusId));
            tr.append(String.format('<td class="gep-selectionname">{0} {1} {2}</td>', GBEUtils.getEventName(order.eventClassifierFullName()), gep._settings.resources.general.polarity[order.polarityId], order.selectionName()));
            tr.append(String.format('<td class="gep-odds betSlipRowPrice">{0}</td>', order.averageMatchedPrice));
            tr.append(String.format('<td class="gep-unmatched betSlipRowStake">{0}</td>', com.base.formatDecimal(order.requestedStake - order.matchedStake,2)));
            tr.append(String.format('<td class="gep-matched">{0}</td>', com.base.formatDecimal(order.matchedStake,2)));
            tr.append(String.format('<td class="gep-action"><span  class="gep-icon"/></td>', order.orderStatusId));


             //var tablerow = $(String.format('#order_{0}',order.orderId), _table);
            //(function (_table, tr, i, unmatchedStake, tablerow) {
            if(unmatchedStake > 0)//part matched
            {

                $('.gep-unmatched', tr).gep_inputcontrol({
                    type:'STAKE', 
                    ccSymbol:clientObject.state.ccSymbol,
                    value: unmatchedStake,  
                    decimalValue:unmatchedStake,
                    onMouseWheeled: function(e, ev){
                        gep.inputControlWheeled(e, ev);
                        gep.calculateRowProfit(e, false);
                        return false;
                        },
                    onArrowClicked: function(e){
                        gep.onArrowClick(e);
                        return false;
                        }
                    });

                    //$('.gep-unmatched', tr).html($('.gep-unmatched', tr).html());


                $('.gep-odds', tr).gep_inputcontrol({
                    type:'PRICE', 
                    value:order.requestedPrice, 
                    decimalValue:order.requestedPrice,
                    onMouseWheeled: function(e, ev){
                        gep.inputControlWheeled(e, ev);
                        gep.calculateRowProfit(e, false);
                        return false;
                    },
                    onArrowClicked: function(e){
                        gep.onArrowClick(e);
                        return false;
                    }
                    });

                $('.gep-action .gep-icon', tr).addClass("gep-icon-delete");

                $('.gep-icon-delete', tr).bind("click", function(){
                    alert("delete");
                    toggleCurrentBetSlipBet(this);
                    return false;
                });

            }


            // })(_table, tr, i, unmatchedStake, tablerow);

            return tr;

}

textbox プラグインは、入力ボックスと 2 つのアンカー タグを含むテーブルを作成します。

/********************
GEP.gep_inputcontrol // stake input, price input box
********************/
(function ($) {

var _templatePrice = $('<table class="gep-inputcontrol" cellpadding="0" cellspacing="0"><tr><td rowspan="2"><input type="text" size="5" class="gep-inputcontrol-price" /></td><td><a tabindex="-1" href="javascript:void(0);" class="gep-inputup"></a></td></tr><tr><td> <a tabindex="-1" href="javascript:void(0);" class="gep-inputdown"></a> </td></tr></table>');
var _templateStake = $('<table class="gep-inputcontrol" cellpadding="0" cellspacing="0"><tr><td rowspan="2"><span class="gep-ccsymbol" /> <input type="text" size="5" class="gep-inputcontrol-stake" /> </td> <td> <a tabindex="-1" href="javascript:void(0);" class="gep-inputup"></a></td></tr><tr><td> <a tabindex="-1" href="javascript:void(0);" class="gep-inputdown"></a> </td></tr> </table>');
var _template;


var _settings = null;
var _instance;
var methods = {
    init: function (options) {
        _settings = options;
        //options.type = 'STAKE'or 'PRICE'

        _template = (options.type == 'STAKE')? _templateStake: _templatePrice;

        $('.gep-ccsymbol',_template).html(options.ccSymbol);




        this.html(_template);
        $('input', this).attr('value', options.value);
        $('input', this).attr('initialvalue', options.decimalValue);
        $('input', this).attr('decimalValue', options.decimalValue);


        $('input', this).bind("mousewheel", function (ev) {
            _settings.onMouseWheeled.call(null, this, ev.originalEvent);
        });      

        $('.gep-inputup', this).bind("click", function (e) {
            _settings.onArrowClicked.call(null, this);
        });            
        $('.gep-inputdown', this).bind("click", function (e) {
            _settings.onArrowClicked.call(null, this);
        });


        _instance = this;
        return this;

    },
    show: function (params) {
        alert("show" + params);
    },
    hide: function () {
        // GOOD
    },
    update: function (content) {
        // !!! 
    }
};

$.fn.gep_inputcontrol = function (method) {

    // Method calling logic
    if (methods[method]) {
        return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
    } else if (typeof method === 'object' || !method) {
        return methods.init.apply(this, arguments);
    } else {
        $.error('Method ' + method + ' does not exist on jQuery.gep_inputcontrol');
    }

};

})(jQuery);

もう少し詳しく説明するために、いくつかの小さな単体テストを行いました

これは動作します..

$('.gep-odds', clientObject.liveBetsPane).gep_inputcontrol({
        type: 'PRICE',
        value: 5,
        decimalValue: 5,
        onMouseWheeled: function (e, ev) {
            gep.inputControlWheeled(e, ev);
            gep.calculateRowProfit(e, false);
            return false;
        },
        onArrowClicked: function (e) {
            gep.onArrowClick(e);
            return false;
        }
    });

これは機能しません...(最後の行にTEXTボックスを配置するだけです)しかし、各行の値が必要なので、このようにする必要があります。

$('.gep-odds', clientObject.liveBetsPane).each(function () {
    $(this).gep_inputcontrol({
        type: 'PRICE',
        value: 5,
        decimalValue: 5,
        onMouseWheeled: function (e, ev) {
            gep.inputControlWheeled(e, ev);
            gep.calculateRowProfit(e, false);
            return false;
        },
        onArrowClicked: function (e) {
            gep.onArrowClick(e);
            return false;
        }
    });
});
4

1 に答える 1

0

テンプレートからドルを削除したところ、うまくいきました。

var _templatePrice = $('<table cla...

現在は
var _templatePrice = '<table cl...

最後の行にhtmlを設定しますが、他の行に移動していました。

私のおかげで.... :)

于 2013-03-21T17:42:37.440 に答える