如何解决如何在屏幕上显示数据并刷新数据?
我使用Xamarin.Forms.Maps并显示我的位置和汽车在范围内。我每5秒向数据库发送一次请求,以获取有关坐标的信息。如何显示地图上的图钉,并在5秒钟后用地图上的新坐标刷新此图钉? 我的代码在这里,但是不起作用。
function woocommerce_ajax_add_to_cart() {
ob_start();
if ( !isset( $_POST[ 'product_id' ] ) ) {
return;
}
$found = false;
$base = true;
if ( $base ) { /** Your condition here **/
// If there was an error adding to the cart,redirect to the product page to show any errors.
$data = array(
'error' => true,'product_url' => apply_filters( 'woocommerce_cart_redirect_after_error',get_permalink( $product_id ),$product_id ),);
wp_send_json( $data );
}else{
if ( sizeof( WC()->cart->get_cart() ) > 0 ) { //check if product already in cart
foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
$_product = $values['data'];
if ( $_product->id == $product_id )
$found = true;
}
if ( ! $found ){ // if product not found,add it
WC()->cart->add_to_cart( $product_id,$quantity,$variation_id,$variation );
}
} else {
WC()->cart->add_to_cart( $product_id,$variation ); // if no products in cart,add it
}
}
}
add_action( 'woocommerce_add_to_cart','woocommerce_ajax_add_to_cart' );
我的方法不起作用
function woocommerce_ajax_add_to_cart() {
ob_start();
if ( !isset( $_POST[ 'product_id' ] ) ) {
return;
}
$found = false;
$base = true;
if ( sizeof( WC()->cart->get_cart() ) > 0 ) { //check if product already in cart
foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
$_product = $values['data'];
if ( $_product->id == $product_id )
$found = true;
}
if ( ! $found ){ // if product not found,add it
if ( $base ) { /** Your condition here **/
$data = array(
'error' => true,);
wp_send_json( $data );
}else{
WC()->cart->add_to_cart( $product_id,$variation );
}
}
} else {
WC()->cart->add_to_cart( $product_id,add it
}
}
add_action( 'woocommerce_add_to_cart','woocommerce_ajax_add_to_cart' );
解决方法
在Xamarin中,最好使用 Device.StartTimer 。
Device.StartTimer(TimeSpan.FromSeconds(5),()=> {
RotateCars();
return true;
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。