gpt4 book ai didi

javascript - 实现 Bootstrap 进度条以通知用户类(class)进度

转载 作者:行者123 更新时间:2023-12-02 14:56:36 25 4
gpt4 key购买 nike

我一直在互联网上寻找如何创建一个进度条,通知用户他们已经完成了多少工作。我理解 HTML 部分,如 Bootstrap's website. 所示但是,我不明白应该如何使用 JavaScript 从 view code api 检索到的用户数据(指示已获取的类和剩余的类)来显示进度用户进度条。

任何帮助/解释(你的思考过程是什么?有关于这方面的好的教程吗?),这个菜鸟非常感谢!我希望保持最佳实践和表现,因为我仍在学习。谢谢!

我正在查看 Stacks 问题,其中包含 user input更改进度条(不太正确),time incrementation ,另一个使用 checkboxes改变进度条(重点是这里的JS代码)。

当前使用:Python 2.7、Pyramid(Web 框架)、Boostrap/Jinja2 模板

<小时/>

查看代码:

@view_config(route_name='assessments', request_method='GET', renderer='templates/unique_assessments.jinja2', permission='create')
def view_unique_microseries_group(request):
logged_in_userid = authenticated_userid(request)
if logged_in_userid is None:
raise HTTPForbidden()

all_assessments = api.retrieve_assessments() #all assessments in a list

#url = HTTPSeeOther(location=request.route_url('microseries'))
return {'logged_in': logged_in_userid, 'all_assessments': all_assessments}


@view_config(route_name='microseries', request_method='GET', renderer='templates/assessments.jinja2', permission='create')
def view_microseries_subseries(request):
logged_in_userid = authenticated_userid(request) #Authenticated User
if logged_in_userid is None:
raise HTTPForbidden()

microseries = int(request.matchdict['id']) #grabs class no. from link in assessments
microseries_list = api.retrieve_assessment(microseries=microseries)
#print 'microseries_list', microseries_list #prints all the matching number of microseries

all_assessments = api.retrieve_assessments() #all assessments in a list
user_results = api.retrieve_assessment_results() #all user results in a list

completed_assessments = []
pending_assessments = []

for assessment in all_assessments:
if assessment is None: # assumes None
continue

found_assessment_result = False
for result in user_results:
if result.owner.username == logged_in_userid and result.assessment == assessment:
found_assessment_result = True # assign Boolean statement
break # no need to check further

if found_assessment_result:
completed_assessments.append(assessment)
else:
pending_assessments.append(assessment)

message = 'Completed'

return {'completed_assessments': completed_assessments, 'pending_assessments': pending_assessments, 'logged_in': logged_in_userid, 'message': message, 'all_assessments':all_assessments, 'microseries_list': microseries_list}

显示整个类(class)目录的主页 HTML模板:unique_assessments.jinja2

    <!-- Stats Gallery Section with Progress bar in each thumbnail-->
<div class="container">
<div class= 'gallery'>
<div class="row">
<div class="col-sm-8 col-md-3 ">
<div class="thumbnail">
<a href="{{request.application_url}}/microseries/1">
<img src="{{request.static_url('img.png')}}" alt="Training" class="img-responsive" style="width: 200px; height: 100px;"/>
</a>
<h4>Video Series 1</h4>
<p class="tag">Contains Episodes 1A-1F </p>
<div class="progress">
<div class="progress-bar progress-bar-striped" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%"> 100%
</div>
</div>
<p class="text_column"></p>
</div>
</div><!-- /.col-->

<div class="col-sm-8 col-md-3 ">
<div class="thumbnail">
<a href="{{request.application_url}}/microseries/2">
<img src="{{request.static_url('img.png')}}" alt="Training" class="img-responsive" style="width: 200px; height: 100px;"/>
</a>
<h4>Video Series 2</h4>
<p class="tag">Contains Episodes 2A-2E </p>
<div class="progress">
<div class="progress-bar progress-bar-info progress-bar-striped" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: 20%"> 20%
</div>
</div>
<p class="text_column"></p>
</div>
</div><!-- /.col-->

<div class="col-sm-8 col-md-3 ">
<div class="thumbnail">
<a href="{{request.application_url}}/microseries/3">
<img src="{{request.static_url('img.png')}}" alt="Training" class="img-responsive" style="width: 200px; height: 100px;"/>
</a>
<h4>Video Series 3</h4>
<p class="tag">Contains Episodes 3A-3G </p>
<div class="progress">
<div class="progress-bar progress-bar-info progress-bar-striped" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: 60%"> 60%
</div>
</div>
<p class="text_column"></p>
</div>
</div><!-- /.col-->

<div class="col-sm-8 col-md-3 ">
<div class="thumbnail">
<a href="{{request.application_url}}/microseries/4">
<img src="{{request.static_url('img.png')}}" alt="Training" class="img-responsive" style="width: 200px; height: 100px;"/>
</a>
<h4>Video Series 4</h4>
<p class="tag">Contains Episodes 4A-4E </p>
<div class="progress">
<div class="progress-bar progress-bar-info progress-bar-striped" role="progressbar" aria-valuenow="80" aria-valuemin="0" aria-valuemax="100" style="width: 80%"> 80%
</div>
</div>
<p class="text_column"></p>
</div>
</div><!-- /.col-->

<div class="col-sm-8 col-md-3 ">
<div class="thumbnail">
<a href="{{request.application_url}}/microseries/5">
<img src="{{request.static_url('img.png')}}" alt="Training" class="img-responsive" style="width: 200px; height: 100px;"/>
</a>
<h4>Video Series 5</h4>
<p class="tag">Contains Episodes 5A-5G </p>
<div class="progress">
<div class="progress-bar progress-bar-info progress-bar-striped" role="progressbar" aria-valuenow="80" aria-valuemin="0" aria-valuemax="100" style="width: 80%"> 80%
</div>
</div>
<p class="text_column"></p>
</div>
</div><!-- /.col-->
</div><!-- /.row-->
</div><!-- Gallery Container Ends -->

JS代码:不确定如何让它与来自 View 代码的数据交互

最佳答案

您不需要任何 JavaScript 来显示进度条。当用户更改页面上的某些内容而无需重新加载页面时,您可能需要一些 JavaScript 来更新进度栏,据我所知,这不是您的情况。

进度条基本上是两个嵌套的 div;内部 div 使用 CSS 着色,其宽度设置为其父级宽度的给定百分比。您所需要的只是在模板中生成正确的标记。

<div class="progress">
<div class="progress-bar" ... style="width: {{course_completion_percent}}%;">
{{course_completion_percent}}%
</div>
</div>

(当然,在您的 View 函数中,您需要计算course_completion_percent变量并将其传递给模板)。像这样的事情会做:

course_completion_percent = 100.0 * len(completed_assessments) / len(all_assessments)

return {
...
'course_completion_percent': course_completion_percent,
}

关于javascript - 实现 Bootstrap 进度条以通知用户类(class)进度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35754960/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com