我有一条动态路线:
test/[id].js
Run Code Online (Sandbox Code Playgroud)
当用户单击指向/test/1Next.js 的链接时,最终会按预期呈现正确的页面。
当我想用/test/1其他东西掩盖 url 时,有趣的事情就开始了。
<Link href="/test/1" as="/any/thing/here">
据我了解,上面的代码应该:
发生的情况是它根本不指向 test/[id].js,只是返回 404。
带有损坏代码的沙箱链接:
https://codesandbox.io/s/nervous-silence-z62s1?file=/pages/index.js
我在这里做错了什么?我有一个非常长且复杂的网址,其中有很多斜杠,我必须与 Next.js 动态路由一起使用,除了使用“as”之外,我没有看到任何其他解决方案......我非常确定我曾经使用过几年前就成功了!似乎它也适用于这个人:Linking todynamic paths in Next.js
如果 Next.js 更改了某些内容,那么我如何轻松地重新创建此功能?
我有一个清单:
<ul>
<li><h2>Header</h2><p>Text</p></li>
<li><h2>Header</h2><p>Text</p></li>
<li><h2>Header</h2><p>Text</p></li>
</ul>
Run Code Online (Sandbox Code Playgroud)
标题文本显示为Cufon生成的画布.
我正在克隆我的列表并使用第二个作为Quicksand脚本的替代品.
一切都像预期的那样工作,但是在排序后标题是不可见的(但画布仍在那里!).
如何解决?
实例:
http://bartekka.ayz.pl/quicksand/
(点击链接后,每个"Cufon Title"都会消失,删除Cufon.now()有帮助,但这不是答案,因为我的项目需要这部分代码)
当"悬停"触发此代码时:
jQuery('#test').animate({opacity: 1},300);
Run Code Online (Sandbox Code Playgroud)
并且用户徘徊并且非常快速地停止"#test"项目长时间闪烁(当然,不透明度在悬停时被动画为1并且在取消悬停时被动画为0).
添加stop()总是对我有用:
jQuery('#test').stop().animate({opacity: 1},300);
Run Code Online (Sandbox Code Playgroud)
关键是我必须使用fadeIn()和fadeOut(),我不知道在这种情况下如何避免闪烁?
实例:http://jsfiddle.net/caHq5/(将指针从黑暗方块快速移动到背景,然后移动到正方形,然后移动到背景等等).stops()什么都不做.
我正在学习 JavaScript,我想知道为什么会这样:
document.getElementById('partofid'+variable+number) 不起作用?
这是示例和JSfiddle链接,我希望“下一步”按钮删除显示的项目并显示下一个。
HTML:
<div id="div-1"> 1 </div>
<div id="div-2" style="display: none"> 2 </div>
<div id="div-3" style="display: none"> 3 </div>
<div id="div-4" style="display: none"> 4 </div>
<a id="next" href="#">next</a>
Run Code Online (Sandbox Code Playgroud)
JS:
var counter = 1;
var button = document.getElementById('next');
button.addEventListener("click",function(){
var currentDiv = document.getElementById('div-'+counter);
currentDiv.remove();
var nextDiv = document.getElementById('div-'+counter+1);
alert(nextDiv); // why does it return null
alert('div-'+counter+1); // while this doesn't?
nextQuestion.style.display = "block";
counter++;
},true);
Run Code Online (Sandbox Code Playgroud) 我是 React 开发的新手,我不确定如何处理这个问题。
我有一个带有路由的简单应用程序,它看起来像这样:
<Router>
<div>
<Route path="/" component={MainComponent} />
<Route path="/dashboard" component={DashboardComponent} />
<Route path="/users" component={UsersComponent} />
<Route path="/admin" component={AdminComponent} />
</div>
</Router>
Run Code Online (Sandbox Code Playgroud)
当我MainComponent按预期访问 localhost:3000/myApp/index.html 我的加载时,它包含站点的主要布局、导航等。
然后我必须点击“仪表板”切换到DashboardComponent“用户”移动到UsersComponent“管理员”加载AdminComponent,这些加载在导航旁边MainComponent。
所以它是这样的:
localhost:3000/myApp = MainComponent
localhost:3000/dashboard = MainComponent + DashboardComponent
localhost:3000/users = MainComponent + UsersComponent
localhost:3000/admin = MainComponent + AdminComponent
Run Code Online (Sandbox Code Playgroud)
我想要实现的是永远不要MainComponent单独加载(因为它除了导航之外什么都没有),而是用它加载 DashboardComponent,所以一切都会像以前一样工作,稍作改动:
localhost:3000/myApp = MainComponent + DashboardComponent
Run Code Online (Sandbox Code Playgroud)
所以我想我想加载我的 MainComponent,然后在 init 上加载仪表板。如果 URL 也从 index.html 自动更改为 /dashboard,那就太好了。
我尝试在 MainComponent.jsx 中做这样的事情:
componentWillMount() { …Run Code Online (Sandbox Code Playgroud) 我开始学习Redux并且整个想法看起来很整洁,但是在将我的React应用程序从"正常"重建为"redux-way"之后,出现了这个问题.
我有一个列表,列出了我基于异步调用的JSON构建的项目.然后该列表上的每个项目都会在点击时发送异步调用并返回一些内容.
在我的应用程序非常简单之前:
components/list/List.jsx
components/list/ListItem.jsx
Run Code Online (Sandbox Code Playgroud)
现在它看起来像这样:
footer/list/ListContainer.jsx // here I run an async call and generate list
footer/list/List.jsx // dumb component creating the whole list full of ListItemContainer components as <li>
footer/list/ListItemContainer.jsx // here I run another async for each <li>
footer/list/ListItem.jsx // dumb component containing <li>
Run Code Online (Sandbox Code Playgroud)
IMO要复杂得多,但还有另外一个问题.
每次我点击我的<li>组件我想触发一个动作然后做一些事情,我的问题是:我可以在ListItem.jsx中做到吗?我不这么认为,因为它是一个愚蠢的组成部分?
这是我的ListItem.jsx:
import React from 'react';
import { connect } from 'react-redux';
// some other imports
class ListItem extends React.Component {
render(props) {
return (
<li>
<a href="#" onClick={//can I …Run Code Online (Sandbox Code Playgroud) 我想为每个有2个以上孩子的项添加"任何东西".不幸的是我的代码不起作用,我想我必须定义(这个)并且可能使用每个,但我不知道该怎么做.
这是我的代码:
if ( jQuery('#container .document').children().size() > 2 ) {
jQuery(this).addClass("anything");
}
Run Code Online (Sandbox Code Playgroud)
一个破碎的例子:
我有一个PHP函数返回一些东西:
function myfunction() {
$array = array('one', 'two', 'three', 'four');
foreach($array as $i) {
echo $i;
}
}
Run Code Online (Sandbox Code Playgroud)
另一个函数,我想从上面的函数传递返回值:
function myfunction2() {
//how to send myfunction()'s output here? I mean:
//echo 'onetwothreefour';
return 'something additional';
}
Run Code Online (Sandbox Code Playgroud)
我想它会看起来像,myfunction2(myfunction)但我不太了解PHP,我无法使它工作.
在撇号内输出 PHP 代码的首选方式是什么?例如,这段 JavaScript 代码会中断,第二行将完全为空:
var jsString = '<div id="content">'+'<?php echo $something['1'] ?>'+'</div>';
Run Code Online (Sandbox Code Playgroud)
谢谢!我知道这是基本的,我知道如何解决它,但我想知道如何以正确的方式做到这一点?
[编辑]
我知道这看起来很明显,但$something["1"]行不通。也同样如此$something[\'1\']。
过去几个月我一直在控制台中使用 git,感觉打字有点太多了。
这是我的流程(假设我在foo分支):
[ ... working ... ]
git add .
git commit -m "Commit message"
git pull origin foo
git push origin foo
Run Code Online (Sandbox Code Playgroud)
我知道这是第一世界的问题之一,但是有没有办法减少这里的打字?我可以只使用git pullandgit push例如吗?git push,有什么区别git push origin foo?