Frage

The "dt" value in the addFormData() function:

[Object {'name':'val1', 'value': 'ww'}]

But I want convert to string and delete the '[Object' and ']' parts:

{'name':'val1', 'value': 'ww'}

Then add to the "params":

$("#flex1").flexOptions({params: [{'name':'options', 'value': '<?php echo($flexiOptions); ?>'},{'name':'model', 'value': 'Product'},{'name':'val1', 'value': 'ww'}]});

My full code:

<?php
$flexiOptions = serialize(
                            array(
                                'fields' => array('Product.id', 'Coupon.id', 'Order.id', 'Order.order_code', 'Product2.name', 'Coupon.code', 'Coupon.date_add', 'Coupon.status'),
                                'conditions' => array('Product.shop_id ='.$shopId),
                                'joins' => array(
                                            array('table' => $prefix.'order_items',
                                                    'alias' => 'OrderItem',
                                                    'type' => 'inner',
                                                    'conditions' => array('Product.id = OrderItem.product_id')
                                                    ),
                                            array('table' => $prefix.'products',
                                                    'alias' => 'Product2',
                                                    'type' => 'inner',
                                                    'conditions' => array('Product.id = Product2.id')
                                                    ),
                                            array('table' => $prefix.'coupons',
                                                    'alias' => 'Coupon',
                                                    'type' => 'inner',
                                                    'conditions' => array(
                                                                        'OrderItem.id = Coupon.order_item_id',
                                                                        'Coupon.shop_id ='.$shopId
                                                                        )
                                                    ),
                                            array('table' => $prefix.'orders',
                                                    'alias' => 'Order',
                                                    'type' => 'inner',
                                                    'conditions' => array('Order.id = OrderItem.order_id')
                                                    ),
                                                )
                                )
                        );

$flexigrid_settings = "
                    //params: 
                        //[
                        //{'name':'options', 'value': '".$flexiOptions."'},
                        //{'name':'model', 'value': 'Product'}
                        //],
                    colModel :
                        [
                        {display: 'ID', name : 'Coupon.id', sortable : true, align: 'left'},
                        {display: 'Rendelés kód', name : 'Order.order_code', sortable : true, align: 'left'},
                        {display: 'Rendelés megnyitása', name : 'Order.id', sortable : true, align: 'left', process:flexOrderOpen},
                        {display: 'Tétel elnevezése', name : 'Product2.name', sortable : true, align: 'left'},
                        {display: 'Kupon kód', name : 'Coupon.code', sortable : true, align: 'left'},
                        {display: 'Létrehozva', name : 'Coupon.date_add', sortable : true, align: 'left'},
                        {display: 'Státus', name : 'Coupon.status', sortable : true, align: 'left', process:flexStatus},
                        ],
                    searchitems :
                        [
                        {display: 'Tétel elnevezése', name : 'Product2.name', isdefault: true}
                        ],
                    ";
?>
<form id="flexiSform">
Kuponkód: <input type="text" name="val1" value="ww">
</form>
<table id="flex1" style="width:auto;"></table>
<script type="text/javascript">

function flexOrderOpen( celDiv, id) {
    $( celDiv ).ready( function() {
        $( celDiv ).html('<a href="/admin/orders/open/'+$( celDiv ).html()+'">rendelés megnyitása</a>');
    });
    }

function flexStatus( celDiv, id) {
    $( celDiv ).ready( function() {
        if ($(celDiv).html() == 0)
            {
            $(celDiv).html('Beváltatlan');
            }
        else
            {
            $(celDiv).html('Beváltott');
            }
    });
    }

$("#flex1").flexigrid({
            url: '/flexi_grids/listsjson/',
            <?php print($flexigrid_settings); ?>
            title: 'Kuponok listája',
            onSubmit: addFormData,
        });

function addFormData(){
    var dt = $('#flexiSform').serialize();
    $("#flex1").flexOptions({params: [{'name':'options', 'value': '<?php echo($flexiOptions); ?>'},{'name':'model', 'value': 'Product'},dt]});
    return true;
}

$('#flexiSform').submit(function (){
    $('#flex1').flexOptions({newp: 1}).flexReload();
    return false;
});
</script>
War es hilfreich?

Lösung

The output you showed does not seem to be from .serialize because .serialize returns are string.

In any case, you don't want to convert anything to a string, it seems you want to add an object to the params array. Use .serializeArray instead and add dt[0] to the array:

function addFormData(){
    var dt = $('#flexiSform').serializeArray();
    $("#flex1").flexOptions({params: [
        {'name':'options', 'value': '<?php echo($flexiOptions); ?>'},
        {'name':'model', 'value': 'Product'},
        dt[0]
    ]});
    return true;
}

Or concatenate both arrays if you want to add all values from the form:

$("#flex1").flexOptions({params: [
    {'name':'options', 'value': '<?php echo($flexiOptions); ?>'},
    {'name':'model', 'value': 'Product'}
].concat(dt)});
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top