如何将jquery对象转换为字符串
How could I convert jquery object to string?
addFormData()
函数中的"dt"值:
[Object {'name':'val1', 'value': 'ww'}]
但我想转换为字符串并删除'[Object'和']'部分:
{'name':'val1', 'value': 'ww'}
然后添加到"params":
$("#flex1").flexOptions({params: [{'name':'options', 'value': '<?php echo($flexiOptions); ?>'},{'name':'model', 'value': 'Product'},{'name':'val1', 'value': 'ww'}]});
我的完整代码:
<?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>
您显示的输出似乎不是来自.serialize
,因为.serialize
返回的是字符串。
在任何情况下,您都不想将任何内容转换为字符串,似乎您想向params
数组中添加一个对象。改为使用.serializeArray
,并将dt[0]
添加到阵列:
function addFormData(){
var dt = $('#flexiSform').serializeArray();
$("#flex1").flexOptions({params: [
{'name':'options', 'value': '<?php echo($flexiOptions); ?>'},
{'name':'model', 'value': 'Product'},
dt[0]
]});
return true;
}
或者,如果您想添加表单中的所有值,请连接两个数组:
$("#flex1").flexOptions({params: [
{'name':'options', 'value': '<?php echo($flexiOptions); ?>'},
{'name':'model', 'value': 'Product'}
].concat(dt)});
相关文章:
- 如何使用JQuery在Javascript中转换字符串中的HTML元素
- 将JSON插入MongoDB中,自动转换字符串中的日期
- 以点表示法转换字符串以获取对象引用
- 在 JavaScript 中转换字符串 11/28/2014 11:00 AM 到现在
- 为什么在主干的字符串数组中转换字符串数组
- 如何简单地转换字符串
- AngularJS如何转换字符串“;yyyyMMdd”;迄今为止
- 如何防止htmlspecialchar(PHP)转换字符串中的整数
- 刷新Aurelia中的i18n转换字符串插值
- 发布时禁用转换字符串
- 转换字符串货币
- 在javascript ajax调用中转换字符串到数组
- 转换字符串包含时间到24小时的时间,我可以做数学与- jQuery
- IE javascript引擎在转换字符串到日期时呈现NaN
- 如何转换字符串“a,b,c,d……”成a.b (c, d . .);来执行
- 如何在javascript中转换字符串到日期格式
- 如何在嵌套数组中转换字符串数组
- 在javascript中转换字符串日期
- 转换字符串在印度格式的javascript
- Javascript转换字符串到数组的对象