Javascript 如何通过单击“下一步”按钮,使用angular js将具有不同数据的同一页面转到laravel
我有一个JSON数据,它有一个问题:数据是什么Javascript 如何通过单击“下一步”按钮,使用angular js将具有不同数据的同一页面转到laravel,javascript,angularjs,laravel,Javascript,Angularjs,Laravel,我有一个JSON数据,它有一个问题:数据是什么 { "id": 51, "question_title": "this is title of Write Essay", "media_type": null, "media_link": null, "question": "This is summary of the write essay of the questions. This will show the questions of the wr
{
"id": 51,
"question_title": "this is title of Write Essay",
"media_type": null,
"media_link": null,
"question": "This is summary of the write essay of the questions. This will show the questions of the write essay.",
"categoryID": 2,
"subcategoryID": 7,
},
{
"id": 54,
"question_title": "this is title of Write Essay",
"media_type": null,
"media_link": null,
"question": "This is questions. This will show the questions of the write essay with the title of the array and the question of the data",
"categoryID": 2,
"subcategoryID": 7,
}
我想通过单击页面上的“下一步”按钮,在不重新加载页面JST的情况下在同一页面上回答下一个问题。我如何才能做到这一点。我的html代码是
@foreach($qus形式的问题)
{{$qus->问题}
@endforeach
00:00:10
@{current.note}
@{{d.Value}}
削减
复制
粘贴
重新启动
答复
以前的
选择:
1.
2.
3.
4.
下一个
var app=angular.module('summary-writed-text',['ngclipboard']);
app.controller('summaryController',函数($scope){
变量问题=$(“#问题”).text();
$scope.Data=[{
索引:0,
注意:“1.阅读下面的文章并用一句话进行总结。在屏幕底部的方框中键入你的回答。你有10分钟的时间完成这项任务。你的回答将根据你的写作质量和你的回答在文章中的关键点上表现得如何来判断。”,
信息:
}, ]
$scope.current=$scope.Data[0],
$scope.next=函数(){
var i=$scope.getIndex($scope.current.index,1);
$scope.current=$scope.Data[i];
},
$scope.previous=函数(){
var i=$scope.getIndex($scope.current.index,-1);
$scope.current=$scope.Data[i];
},
$scope.getIndex=函数(currentIndex,shift){
var len=$scope.Data.length;
返回((当前索引+移位)+len)%len)
}
});
如何在我的应用程序中获得这种类型的功能?您可以在Blade中的
@foreach
中使用$key=>$value
符号来获取JSON中的值索引,然后使用ng show指令在控制器中使用范围变量来显示它
例如:
@foreach($question as $key => $qus)
<div ng-show="current.index == {{$key}}">{{$qus->question}}</div>
@endforeach
@foreach($key=>$qus的问题)
{{$qus->问题}
@endforeach
避免对HTML中的不同元素使用相同的ID好的,很抱歉,我没有注意到您的
current
变量是一个对象,那么您的数字索引是current。index
而不仅仅是current
,而且您的上一个按钮没有在ng单击中引用正确的函数。答案已被编辑