オブジェクトを配列に格納することに関して問題があります。しかし、$.inArray を使用してオブジェクトの存在を確認しようとすると、常に -1 が返されます。私はangularjsを使用しています。
<input name="{{question.number}}"
ng-click="radioSelected(question.choiceOneWeight, question.number,question.tmiGroup)"
type="radio" value="{{question.choiceOneWeight}}" />
$scope.radioSelected = function(choice, question, tmiGroup) {
var answer = {};
answer.questionNumber = question;
answer.answerWeight = choice;
answer.tmiGroup = tmiGroup;
if($.inArray(answer,userAnswers) < 0){
userAnswers.push(answer);
}
};
私の生成された回答オブジェクトは
{"questionNumber":23,"answerWeight":1,"tmiGroup":"JP"}
ラジオボタンを複数回クリックすると、
userAnswers 配列は次のようになります。
[{"questionNumber":23,"answerWeight":1,"tmiGroup":"JP"},
{"questionNumber":23,"answerWeight":1,"tmiGroup":"JP"},
{"questionNumber":23,"answerWeight":1,"tmiGroup":"JP"},
{"questionNumber":23,"answerWeight":1,"tmiGroup":"JP"},
{"questionNumber":23,"answerWeight":1,"tmiGroup":"JP"},
{"questionNumber":23,"answerWeight":1,"tmiGroup":"JP"},
{"questionNumber":23,"answerWeight":1,"tmiGroup":"JP"},
{"questionNumber":23,"answerWeight":1,"tmiGroup":"JP"},
{"questionNumber":23,"answerWeight":1,"tmiGroup":"JP"},
{"questionNumber":23,"answerWeight":1,"tmiGroup":"JP"},
{"questionNumber":23,"answerWeight":1,"tmiGroup":"JP"},
{"questionNumber":23,"answerWeight":1,"tmiGroup":"JP"},
{"questionNumber":23,"answerWeight":1,"tmiGroup":"JP"},
{"questionNumber":23,"answerWeight":1,"tmiGroup":"JP"},
{"questionNumber":23,"answerWeight":1,"tmiGroup":"JP"},
{"questionNumber":23,"answerWeight":1,"tmiGroup":"JP"},
{"questionNumber":23,"answerWeight":1,"tmiGroup":"JP"}]