正如标题所示,我有一个问题,我做了下拉.它包含商店可以运送的国家/地区列表.它可以创建一个运输区域,为其命名,然后选择属于该区域的所有国家/地区.然后为它添加价格.
在结账时我想获得网上商店提供的国家列表并使用它,以便客户可以选择他住的地方.该国的选择是商店也出货的产品.但是我遇到了一些问题.
主要的问题是它的构造方式是选择一个区域,该区域将使用URL中的额外参数重新加载页面,这将把运送区域添加到即将创建的订单中.这会导致我的下拉问题.因为它总是选择下拉的底部选项而不是我刚刚选择的那个,这意味着我无法正确设置该人居住的国家.
所以,如果下拉是
美国
中国
我选择美国页面将重新加载,中国将徘徊
我的代码:
下拉html
{% for shippingRegion in store.getShippingRegions %}
{% endfor %}
Select a shipping region
{% for key,country in regionCountries %}
{% for c in country %} =
{{c}}
{% endfor %}
{% endfor %}
Javascript函数重新加载页面
function shippingRegionSelectCheck(regionSelect){
if(regionSelect){
var selected = $('#shippingRegion').find('option:selected');
var extra = selected.data('id');
var country = $('#shippingRegion').val('value');
var href = $('#addShippingRegion' + extra).attr('href');
window.location.href = href;
}
}
实体
/**
* @ORM\Entity
* @ORM\Table(name="Shipping_Regions")
*/
class ShippingRegion{
public function __construct() {
$this->shipping_weight_prices = new ArrayCollection();
$this->shipping_amount_prices = new ArrayCollection();
}
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string", length=100, nullable=true)
*/
protected $name;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
protected $regionType;
/**
* @ORM\Column(type="array", nullable=true)
*/
protected $regionCountry;
解决方法:
也许是因为你在每个选项中都有“选中”,所以浏览器会选择最后一个选项.
{{c}}
标签:jquery,php,twig,symfony
来源: https://codeday.me/bug/20190701/1351594.html