angularjs动态创建一个字符串数组,然后进行比较
我正在构建一个离子应用程序,如下所示: 申请流程如下:angularjs动态创建一个字符串数组,然后进行比较,angularjs,ionic-framework,Angularjs,Ionic Framework,我正在构建一个离子应用程序,如下所示: 申请流程如下: 用户单击“开始”按钮,然后5秒的计时器开始(用户应记住所有对)。5秒后,在接下来的20秒内,用户应该填写单词前面的对应对。如果他填写了正确的一对,则会给反馈打勾 如果用户填写完正确的配对,他可以单击“停止”按钮 TODO:我有一个由$scope.expectedSequence中的所有对组成的数组,但是我不知道如何构建数组$scope.enteredSequence,然后在$scope.CheckCorrectibility函数中检查它们以
$scope.expectedSequence
中的所有对组成的数组,但是我不知道如何构建数组$scope.enteredSequence
,然后在$scope.CheckCorrectibility
函数中检查它们以进行升级或播放同一级别。到目前为止,我有一个虚拟的检查,使进展。理想情况下,它应该检查以下内容:
if(angular.equals($scope.expectedSequence,$scope.enteredSequence)){…}.controller('DashCtrl', function($scope, $timeout) {
$scope.level=1
$scope.leftList=false
$scope.enterTextView=false
$scope.previewView=false
$scope.promptAction=''
$scope.promptLevel=''
$scope.enteredSequence=[]
$scope.expectedSequece=[]
$scope.show_stop_button=false
$scope.show_start_button=true
$scope.word_pair = [
{'word':'Nitish', 'pair':'Patkar'},
{'word':'Mihir', 'pair':'Janaj'},
{'word':'Jannes', 'pair':'Stubbi'},
{'word':'Martin', 'pair':'Wolle'}
]
$scope.partnerCheckList = {};
for(var v in $scope.word_pair){
$scope.expectedSequece.push($scope.word_pair[v].pair)
console.log($scope.expectedSequece)
$scope.partnerCheckList[$scope.word_pair[v].word] = $scope.word_pair[v].pair;
}
$scope.showPartner = {};
$scope.partnerCheck = function(p,i_p){
if($scope.partnerCheckList[i_p] == p){
$scope.showPartner[p] = true;
}
}
$scope.start = function(){
$scope.show_start_button=false
$scope.leftList=true
$scope.previewView=true
$scope.promptLevel='Level: ' + $scope.level
$scope.counter1=5
$timeout($scope.startFilling, 5000)
$scope.onTimeout = function(){
$scope.counter1--;
mytimeout = $timeout($scope.onTimeout,1000);
if($scope.counter1==0){
$timeout.cancel(mytimeout);
}
}
var mytimeout = $timeout($scope.onTimeout,1000);
}
$scope.startFilling = function(){
$scope.promptLevel='Level: ' + $scope.level
$scope.promptAction='Now enter the corresponding pairs in the right column'
$scope.enterTextView=true
$scope.previewView=false
$scope.show_start_button=false
$scope.show_stop_button=true
$scope.counter2=20
$timeout($scope.checkCorrectness, 20000)
$scope.onTimeout = function(){
$scope.counter2--;
mytimeout = $timeout($scope.onTimeout,1000);
if($scope.counter2==0){
$timeout.cancel(mytimeout);
$scope.enterTextView=false
$scope.previewView=false
$scope.leftList=false
$scope.show_stop_button=false
$scope.show_start_button=true
}
}
var mytimeout = $timeout($scope.onTimeout,1000);
}
$scope.checkCorrectness = function(){
$scope.ok=true
$scope.enterTextView=false
$scope.previewView=true
$scope.promptAction=''
$scope.promptLevel=''
/*dummy check*/
if($scope.ok){
$scope.level= $scope.level + 1
$scope.promptLevel='Level: ' + $scope.level
}
}
})
<ion-view view-title="Dashboard">
<ion-content class="padding">
<div align="center" ng-if="promptLevel">
<h3>{{promptLevel}}</h3>
</div>
<div align="center" ng-if="promptAction">
<h3>{{promptAction}}</h3>
</div>
<div align="center" ng-if="counter1">
<h3>{{counter1}}</h3>
</div>
<div align="center" ng-if="counter2">
<h3>{{counter2}}</h3>
</div>
<div class="row">
<!-- Left half of the screen to hold list of words -->
<div class="col col-50" align="center" style="padding-top:0.2cm;" ng-if="leftList">
<ion-list>
<ion-item ng-repeat="item in word_pair" id="list_one">
<h2>{{item.word}}</h2>
</ion-item>
</ion-list>
</div>
<!-- Right half of the screen to hold list of pairs -->
<div class="col col-50" ng-if="previewView">
<ion-list>
<ion-item ng-repeat="item in word_pair" id="list_two">
<h2>{{item.pair}}</h2>
</ion-item>
</ion-list>
</div>
<div class="col col-50" ng-if="enterTextView">
<ion-list>
<ion-item ng-repeat="item in word_pair" id="list_two">
<input ng-model="pair" type="text" ng-change="partnerCheck(pair,item.word)">
<div ng-show="showPartner[pair]" align="right"><i class="ion-checkmark myCheckmark"></i></div>
</ion-item>
</ion-list>
</div>
</div>
<div align="center" style="padding-bottom:1cm;" ng-if="show_start_button">
<button class="button button-dark start-button" ng-click="start()">Start</button>
</div>
<div align="center" ng-if="show_stop_button">
<button class="button button-dark start-button" >Stop</button>
</div>
</ion-content>
</ion-view>
Mt HTML:
.controller('DashCtrl', function($scope, $timeout) {
$scope.level=1
$scope.leftList=false
$scope.enterTextView=false
$scope.previewView=false
$scope.promptAction=''
$scope.promptLevel=''
$scope.enteredSequence=[]
$scope.expectedSequece=[]
$scope.show_stop_button=false
$scope.show_start_button=true
$scope.word_pair = [
{'word':'Nitish', 'pair':'Patkar'},
{'word':'Mihir', 'pair':'Janaj'},
{'word':'Jannes', 'pair':'Stubbi'},
{'word':'Martin', 'pair':'Wolle'}
]
$scope.partnerCheckList = {};
for(var v in $scope.word_pair){
$scope.expectedSequece.push($scope.word_pair[v].pair)
console.log($scope.expectedSequece)
$scope.partnerCheckList[$scope.word_pair[v].word] = $scope.word_pair[v].pair;
}
$scope.showPartner = {};
$scope.partnerCheck = function(p,i_p){
if($scope.partnerCheckList[i_p] == p){
$scope.showPartner[p] = true;
}
}
$scope.start = function(){
$scope.show_start_button=false
$scope.leftList=true
$scope.previewView=true
$scope.promptLevel='Level: ' + $scope.level
$scope.counter1=5
$timeout($scope.startFilling, 5000)
$scope.onTimeout = function(){
$scope.counter1--;
mytimeout = $timeout($scope.onTimeout,1000);
if($scope.counter1==0){
$timeout.cancel(mytimeout);
}
}
var mytimeout = $timeout($scope.onTimeout,1000);
}
$scope.startFilling = function(){
$scope.promptLevel='Level: ' + $scope.level
$scope.promptAction='Now enter the corresponding pairs in the right column'
$scope.enterTextView=true
$scope.previewView=false
$scope.show_start_button=false
$scope.show_stop_button=true
$scope.counter2=20
$timeout($scope.checkCorrectness, 20000)
$scope.onTimeout = function(){
$scope.counter2--;
mytimeout = $timeout($scope.onTimeout,1000);
if($scope.counter2==0){
$timeout.cancel(mytimeout);
$scope.enterTextView=false
$scope.previewView=false
$scope.leftList=false
$scope.show_stop_button=false
$scope.show_start_button=true
}
}
var mytimeout = $timeout($scope.onTimeout,1000);
}
$scope.checkCorrectness = function(){
$scope.ok=true
$scope.enterTextView=false
$scope.previewView=true
$scope.promptAction=''
$scope.promptLevel=''
/*dummy check*/
if($scope.ok){
$scope.level= $scope.level + 1
$scope.promptLevel='Level: ' + $scope.level
}
}
})
<ion-view view-title="Dashboard">
<ion-content class="padding">
<div align="center" ng-if="promptLevel">
<h3>{{promptLevel}}</h3>
</div>
<div align="center" ng-if="promptAction">
<h3>{{promptAction}}</h3>
</div>
<div align="center" ng-if="counter1">
<h3>{{counter1}}</h3>
</div>
<div align="center" ng-if="counter2">
<h3>{{counter2}}</h3>
</div>
<div class="row">
<!-- Left half of the screen to hold list of words -->
<div class="col col-50" align="center" style="padding-top:0.2cm;" ng-if="leftList">
<ion-list>
<ion-item ng-repeat="item in word_pair" id="list_one">
<h2>{{item.word}}</h2>
</ion-item>
</ion-list>
</div>
<!-- Right half of the screen to hold list of pairs -->
<div class="col col-50" ng-if="previewView">
<ion-list>
<ion-item ng-repeat="item in word_pair" id="list_two">
<h2>{{item.pair}}</h2>
</ion-item>
</ion-list>
</div>
<div class="col col-50" ng-if="enterTextView">
<ion-list>
<ion-item ng-repeat="item in word_pair" id="list_two">
<input ng-model="pair" type="text" ng-change="partnerCheck(pair,item.word)">
<div ng-show="showPartner[pair]" align="right"><i class="ion-checkmark myCheckmark"></i></div>
</ion-item>
</ion-list>
</div>
</div>
<div align="center" style="padding-bottom:1cm;" ng-if="show_start_button">
<button class="button button-dark start-button" ng-click="start()">Start</button>
</div>
<div align="center" ng-if="show_stop_button">
<button class="button button-dark start-button" >Stop</button>
</div>
</ion-content>
</ion-view>
{{Promplevel}}
{{promptAction}}
{{counter1}}
{{counter2}}
{{item.word}
{{item.pair}
开始
停止
通过以下代码修改,我能够获得正确的$scope.enteredSequence
$scope.partnerCheck = function(p,i_p){
if($scope.partnerCheckList[i_p] == p){
$scope.showPartner[p] = true;
$scope.enteredSequence.push(p)
}
}
通过以下代码修改,我能够获得正确的$scope.enteredSequence
$scope.partnerCheck = function(p,i_p){
if($scope.partnerCheckList[i_p] == p){
$scope.showPartner[p] = true;
$scope.enteredSequence.push(p)
}
}
换句话说,您想检查数组是否等于另一个数组(包括顺序)?是正确的。我在partnerCheck()中尝试了类似$scope.enteredSequence.push(p)的东西,但它产生了类似于[“p”、“Pa”、“Pat”、“Patk”、“Patka”、“Patkar”…]的东西。我不明白如何在输入框中构建这样一个由输入的正确值组成的数组。实际上,您的plnkr不完整。我将在稍后更新。换句话说,您想检查数组是否等于另一个数组(包括顺序)?是的,正确。我在partnerCheck()中尝试了类似$scope.enteredSequence.push(p)的东西,但它产生了类似于[“p”、“Pa”、“Pat”、“Patk”、“Patka”、“Patkar”…]的东西。我不明白如何在输入框中构建这样一个输入正确值的数组。实际上,您的plnkr不完整。我将在稍后更新