我正在构建一个界面,您可以在其中选择收音机,它将显示不同的表单元素。
当滑块显示时,值更改将设置到页面上呈现的对象中。
在这个例子中,我有它,所以它确实更新了对象,但滑块不再移动,即使如果您单击该行,该值已正确设置。
https://codesandbox.io/s/shy-dawn-e5zyu
我设置的对象在父对象中声明:
const defaultActivity = {
group: "",
a: 0,
b: 0
};
const [activity, setActivity] = useState(defaultActivity);
Run Code Online (Sandbox Code Playgroud)
然后,在包含滑块的子组件中,该handleChange函数在该组件中使用,并且我还使用父函数来访问setActivity.
const TestSlider = (props) => {
const [value, setValue] = React.useState(0);
const handleChange = (event, newValue) => {
setValue(newValue);
// This sets the slider value to the activity object
// if you comment this line out then the sliders slide correctly
props.onDataChanged(props.name.toLowerCase(), newValue);
};
return (
<React.Fragment>
<Typography id="discrete-slider" gutterBottom>
{props.name}
</Typography>
<Slider
value={value} …Run Code Online (Sandbox Code Playgroud) 我试图从特定帖子中提取摘录和自定义字段,我尝试使用帖子标题和帖子ID,但我只是成功地使用此查询拉每一篇文章.例如,我有这个代码试图拉出id为182的帖子的标题
<?php $map = new WP_Query();
$map->query('post_id=182'); ?>
<?php while ($map->have_posts()) : $map->the_post(); ?
<?php the_title(); ?>
<?php endwhile; ?>
Run Code Online (Sandbox Code Playgroud)
它使用这种方法拉出每个帖子的标题,我无法弄清楚我将如何有这样的多个循环,每个只从一个特定的帖子中提取内容.有人可以解释我哪里出错吗?
我试图用highlight_string显示我的代码.我的所有变量都被剥离了打印的代码.我究竟做错了什么?发生了什么的一个例子......
<?php highlight_string("
<?
$a=3;
$b=4;
if ($a < $b){
echo 'a is less than b';
}
?>");
?>
Run Code Online (Sandbox Code Playgroud)
输出看起来像这样
<?
=3;
=4;
if ( < ){
echo 'a is less than b';
}
?>
Run Code Online (Sandbox Code Playgroud) 我正在使用simplexml_load_string解析xml,如下所示:
$xml = simplexml_load_string($response);
echo '{'.
'"Date":"'.$xml->Date[0].'",'.
'"Description":"'.$xml->ShipTos->ShipTo->ShippingGroups->ShippingGroup->OrderItems->OrderItem->Description[0].'",'.
'"Track":"'.$xml->Shipments->Shipment->Track[0].'"'.
'}';
Run Code Online (Sandbox Code Playgroud)
这可以正常工作,但如果一个节点多次出现在xml中,它只会抓取一次.有人可以帮我理解如何专门为Description节点编写foreach循环吗?
使用wordpress我从帖子中抓取第一个图像附件.这很好用:
<?php
global $post;
$args = array(
'post_parent' => $post->ID,
'post_type' => 'attachment',
'post_mime_type' => 'image',
'orderby' => 'menu_order',
'order' => 'ASC',
'numberposts' => 2 );
$images = get_posts($args);
if ( $images ) {
$i = 0;
while($i <= 1){
$image = wp_get_attachment_url( $images[$i]->ID );
echo "<img src='$image' />";
$i++;
}
}
?>
Run Code Online (Sandbox Code Playgroud)
我也在尝试处理这些图像,这些图像与timthumb一起根据浏览器大小调整图像大小.我只能在两个图像中的一个上工作.我希望它能够记录并调整大小两次,但脚本没有在循环中运行.有人可以帮忙吗?这就是我正在使用的完整剪辑看起来像:
<?php
global $post;
$args = array(
'post_parent' => $post->ID,
'post_type' => 'attachment',
'post_mime_type' => 'image',
'orderby' => 'menu_order',
'order' => 'ASC',
'numberposts' => 2 );
$images …Run Code Online (Sandbox Code Playgroud) 这让我疯了.使用Google Maps v3我使用php加载地图以确定lat long:
function initialize() {
var latlng = "<?php echo $lat;?>,<?php echo $long;?>";
console.log(latlng);
var mapOptions = {
center: new google.maps.LatLng(<?php echo $lat;?>,<?php echo $long;?>),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas")
, mapOptions);
}
Run Code Online (Sandbox Code Playgroud)
这很好用.但是,如果我尝试传入latlng var
center: new google.maps.LatLng(latlng),
Run Code Online (Sandbox Code Playgroud)
地图只显示一个蓝色的屏幕并且坏了(没有缩放或控件或任何东西).控制台日志和源代码看起来正确生成参数.关于可能发生的事情的任何想法?
我确实有initialize(),body但我把它移到(document).ready我的脚本中.对于这个问题,这似乎没有任何区别.
我在网站上生成了一个简单的整数网址,允许用户查看过去的订单.
http://site.com/order_id/145323
问题是只需更改该号码然后查看其他人的订单就很容易了.我想知道在url中编码这个数字的简单方法是什么,然后让php解码它以便它可以运行控制器?它不一定非常安全,因为某些东西使得人们只需更改数字就可以轻松查看数据.我尝试过这样的事情:
order_id/<?php echo base64_encode($theOrder); ?>
然后在我试过的控制器动作中:
if($orderId = (int) $this->getRequest()->getParam('order_id') && Mage::getSingleton('customer/session')->isLoggedIn()){
$orderId = (int) $this->getRequest()->getParam('order_id');
$orderId = base64_decode($orderId);
$order = Mage::getModel('sales/order')->load($orderId);
Mage::register('current_order', $order);
$this->loadLayout();
$this->renderLayout();
}
Run Code Online (Sandbox Code Playgroud)
但这不起作用.什么是在网址中隐藏此参数的好方法?
我为输入字段写了一点检查,计算长度并确保它是适当的数量.它变得复杂,因为它需要允许9位数或1个字母和5位数.我现在的方式有效,但代码伤害了我的大脑,我想看看更优雅的解决方案是什么样的,可能使用三元和/或开关?
所以现在我所拥有的不太漂亮的一小部分:
if (len !== 9) {
if (len == 1) {
y.hide();
n.show();
valInput.text("You need 8 more numbers");
} else {
if (len == 2) {
y.hide();
n.show();
valInput.text("You need 7 more numbers");
} else {
if (len == 3) {
y.hide();
n.show();
valInput.text("You need 6 more numbers");
} else {
if (len == 4) {
y.hide();
n.show();
valInput.text("You need 5 more numbers");
} else {
if (len == 5) {
y.hide();
n.show();
valInput.text("You need 4 more numbers");
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用jQuery加载的单页设计.我有一些主要的导航元素,根据点击的内容,显示或隐藏不同的div.例如html:
<div class="box a">
<div class="inner">
<a class="boxLink circle black" href="#">Link a</a>
</div>
</div>
<div class="box a1 hidden">
<div class="inner circle">
<a class="boxLink" href="#">a1</a>
</div>
</div>
<div class="box a2 hidden">
<p class="green">a2</p>
</div>
<div class="box b">
<div class="inner">
<a class="boxLink circle black" href="#">Link b</a>
</div>
</div>
<div class="box b1 hidden">
<div class="inner circle">
<a class="boxLink" href="#">b1</a>
</div>
</div>
<div class="box b2 hidden">
<p class="green">b2</p>
</div>
Run Code Online (Sandbox Code Playgroud)
和jQuery
$(".a").click(function(){
$('.b').hide();
$('.b1').hide();
$('.b2').hide();
$('.a1').slideDown({
duration:500,
complete:function(){
$('.a2').slideDown('1000');
}
});
return false
});
$(".b").click(function(){ …Run Code Online (Sandbox Code Playgroud) 是否有一个javascript解决方案来读取url,从中创建一个字符串,并根据结果构建一个if语句?有没有人知道一个教程或可以提供一些如何实现这一目标的技巧.
更具体地说,我试图根据搜索结果来做这件事.所以...例如url是这样的:
http://www.site.com/catalogsearch/result?q=asdf&kw=asdf&x=0&y=0
和丹尼尔斯的回应一起工作我正在尝试这个没有运气:
if (window.location.search ==='?q=asdf') {
alert("You searched for asdf");
}
Run Code Online (Sandbox Code Playgroud) javascript ×5
php ×5
wordpress ×2
jquery ×1
loops ×1
magento ×1
material-ui ×1
reactjs ×1
simplexml ×1
xml ×1