我,我在角JS我节省一个JSON清单得分VAR角JS数据推入表不工作
$scope.jobTemplate = [{ type: "AddInstructions", visible: false, buttonText: "Add Instructions", editableInstructionsList: [{ Number: totalEditableInstruction, Text: "Instruction 1"}] },
{ type: "AddSingleQuestionsList", visible: false, buttonText: "Add Ques. (single Ans.)", singleQuestionsList: [{ Number: totalSingleQuestionList, Question: "What is your gender ?", Options: "Male1;Female2"}] },
{ type: "AddMultipleQuestionsList", visible: false, buttonText: "Add Ques. (Multiple Ans.)", multipleQuestionsList: [{ Number: totalMultipleQuestionList, Question: "What is your multiple gender ?", Options: "Malem1;Femalem2"}] },
{ type: "AddTextBoxQuestionsList", visible: false, buttonText: "Add Ques. (TextBox Ans.)", textBoxQuestionsList: [{ Number: totalTextBoxQuestionList, Question: "Who won 2014 FIFA World cup ?", Options: "text"}] },
{ type: "AddListBoxQuestionsList", visible: false, buttonText: "Add Ques. (ListBox Ans.)", listBoxQuestionsList: [{ Number: totalListBoxQuestionList, Question: "What is your multiple gender ?", Options: "Malem1;Femalem2"}] }
];
我推按钮的点击数据如下
// single questions..
$scope.InsertSingleQuestionRow = function() {
totalSingleQuestionList = totalSingleQuestionList + 1;
var singleQuestionsList = { Number: totalSingleQuestionList, Question: $('#SingleQuestionTextBoxQuestionData').val(), Options: $('#SingleQuestionTextBoxAnswerData').val() };
$scope.jobTemplate[1].singleQuestionsList.push(singleQuestionsList);
refreshSingleQuestionsList();
}
虽然在用户界面中新添加的项目正常显示,但是当我试图通过http post发送当前范围变量数据到服务器时,它没有最新的数据。
$scope.ClientCreateTemplateFunction = function() {
var clientCreateTemplateData = $scope.jobTemplate;
var url = ServerContextPah + '/Client/CreateTemplate';
if (true) {
//startBlockUI('wait..', 3);
$http({
url: url,
method: "POST",
data: clientCreateTemplateData,
headers: { 'Content-Type': 'application/json' }
}).success(function (data, status, headers, config) {
//$scope.persons = data; // assign $scope.persons here as promise is resolved here
//stopBlockUI();
}).error(function (data, status, headers, config) {
});
}
else {
$scope.showErrors = true;
showToastMessage("Error", "Some Fields are Invalid !!!");
}
}
我也尝试过全局变量。我不知道为什么范围变量工作正常与用户界面,而不是工作时,通过http发送到服务器相同的数据。 帮助我。
我已经附加了一个快照,其中UI显示两个列表,而当我console.log相同的范围变量它只显示一个列表。
你说的'不具有的意思最新数据“?你是否在发起http请求之前设置了一个断点,并发现$ scope.jobTemplate不是最新的? – runTarm
我已经上传了上传的快照。 –
如果您添加了第三项,会发生什么情况? – runTarm