我正在使用jsonForm从3个不同的json模式生成表单。提交表单时,请求另一个表单,依此类推......所有3个表单上的数据创建一个json对象,在填写完最后一个表单后将其发回并存储。
表单按预期工作,问题是更新列表使用ng-repeat
HTML:
<ul>
<li ng-repeat="names in newName">{{names}}</li>
<ul>
默认名称数组:
$scope.newName= ["test1","test2"];
初始对象
var set1 = {
"setName": "",
"setAttributes": [],
"setQuestions": []
};
角:
$scope.createNewSet = function () {
$http.get('/json/schema1.json').success(function(data) {
$('#form1').jsonForm({ // DISPLAY FIRST FORM
schema: data,
"form": [
"*",
{
"type": "submit",
"title": "Proceed to step 2"
}
],
onSubmit: function (errors, values) {
var sName = values.setName;
set1.setName = sName;
$http.get('/json/schema2.json').success(function(data) {
$('#form2').jsonForm({ //DISPLAY SECOND FORM
schema: data,
"form": [
"*",
{
"type": "submit",
"title": "Proceed to step 3"
}
],
onSubmit: function (errors, values) { // DISPLAY THIRD FORM
set1.setAttributes = values.attributes;
$http.get('/json/schema3.json').success(function(data) {
$('#form3').jsonForm({
schema: data,
"form": [
"*",
{
"type": "submit",
"title": "Proceed to step 4"
}
],
onSubmit: function (errors, values) { // SAVE COMPLETE SET
set1.setQuestions = values.questions;
$scope.newName.push(set1.setName); //UPDATE li
$scope.newName.push('blah')
console.log($scope.newName);
},
});
});
},
浏览器控制台显示带有["test1","test2","Simo","blah"]
和Simo
的更新的newName数组Blah
,但HTML不会显示它们。是否有一些阻止角度更新DOM的东西?
谢谢..
答案 0 :(得分:0)
尝试重新应用范围:
$scope.$apply(function(){
$scope.newName.push(set1.setName); //UPDATE li
$scope.newName.push('blah')
});