我是twitter引导程序的新手.使用导航菜单.我正在尝试将活动类设置为所选菜单.我的菜单是 -
<div class="nav-collapse">
<ul class="nav">
<li id="home" class="active"><a href="~/Home/Index">Home</a></li>
<li><a href="#">Project</a></li>
<li><a href="#">Customer</a></li>
<li><a href="#">Staff</a></li>
<li id="broker"><a href="~/Home/Broker">Broker</a></li>
<li><a href="#">Sale</a></li>
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)
谷歌搜索后我试着跟踪东西,我必须从菜单中设置每个页面上的活动类,如as--
<script>
$(document).ready(function () {
$('#home').addClass('active');
});
</script>
Run Code Online (Sandbox Code Playgroud)
但上面的问题是我设置了默认选择的主菜单.然后它总是被选中.有没有其他方法可以做到这一点?,或者我可以概括并保持我的js在布局文件本身?
执行应用程序后我的菜单看起来

点击其他菜单项后,我得到以下结果 -

我在索引视图和Broker视图中添加了以下脚本---
<script>
$(document).ready(function () {
$('#home').addClass('active');
});
</script>
<script>
$(document).ready(function () {
$('#broker').addClass('active');
});
</script>
Run Code Online (Sandbox Code Playgroud)
分别.
我有此代码来检查用户是否已通过身份验证
const withAuth = AuthComponent => {
class Authenticated extends Component {
static async getInitialProps (ctx) {
let componentProps
if (AuthComponent.getInitialProps) {
componentProps = await AuthComponent.getInitialProps(ctx)
}
return {
...componentProps
}
}
componentDidMount () {
this.props.dispatch(loggedIn())
}
renderProtectedPages (componentProps) {
const { pathname } = this.props.url
if (!this.props.isAuthenticated) {
if (PROTECTED_URLS.indexOf(pathname) !== -1) {
// this.props.url.replaceTo('/login')
Router.replace('/login') // error
}
}
return <AuthComponent {...componentProps} />
}
render () {
const { checkingAuthState, ...componentProps } = this.props
return (
<div>
{checkingAuthState …Run Code Online (Sandbox Code Playgroud) 这是上一个问题的后续,但我将在这里重新发布我的所有代码 -
我想在 Django 中显示列表的内容,并且我在我的模板中使用它 -
<body>
<h1>Testing the class page backend</h1>
<ul>
{ % for author in authors% }
<li>{{ author|safe }}</li>
{ % endfor % }
</ul>
</body>
Run Code Online (Sandbox Code Playgroud)
(由于最后一个问题,我添加了保险箱)为了测试,我还将 searchTerm 设置为等于“Math 51”。作者是由这个函数提供的 -
def getAllInformation(searchTerm, template_name):
searchTerm = "MATH 51"
nameAndNumberStore = modifySearchTerm(searchTerm)
url = modifyUrl(nameAndNumberStore)
soup = getHtml(url)
information = []
if (checkIfValidClass(soup,nameAndNumberStore)):
storeOfEditions = getEdition(soup)
storeOfAuthorNames = getAuthorName(soup)
storeOfBookNames = getBookNames(soup)
storeOfImages = getImages(soup)
information.append(storeOfAuthorNames) #REMEMBER this is a list of two lists
information.append(storeOfEditions)
return render_to_response( …Run Code Online (Sandbox Code Playgroud)