我有一个两层表,我希望为其添加值。该表是动态加载的,当每个文本框加载时,我已经调用了函数发送来自两个ng重复项的函数,以便我可以检查它是哪个单元格文本框,以及是否存在它的值将它添加到ng-model =结果。该函数可以工作,但是,返回的值不会显示在文本框中。我不知道我做错了。这是我的表代码:在ng-init中为每个ng-repeat加载函数不会分配返回值
<div class="divTable">
<div class="divTableHeading">
<div class="divTableRow">
<div class="divTableCell"></div>
<div class="divTableCell" ng-repeat='item in TestingTable[1].EnvironmentTypes'>{{item.Name}}</div>
</div>
</div>
<div class="divTableBody">
<div class="divTableRow" ng-repeat='item in TestingTable[0].TestingType'>
<div class="divTableCell">{{item.Name}}</div>
<div class="divTableCell" ng-repeat="x in TestingTable[1].EnvironmentTypes">
<input type="text" ng-model="result" ng-init="result = loadData(x, $parent.item)">
</div>
</div>
</div>
</div>
而且我与loadData功能的JavaScript代码:
myApp.controller('ctrl', ['$scope', function($scope) {
var initial = 0;
$scope.TestingTable = [{
TestingType: [{
Id: 1,
Name: "Functional Testing"
},
{
Id: 2,
Name: "Regression Testing"
},
{
Id: 3,
Name: "Integration"
},
{
Id: 4,
Name: "BVT"
}
]
},
{
EnvironmentTypes: [{
Id: 1,
Name: "Dev/QE (VCD)"
},
{
Id: 2,
Name: "Staging"
},
{
Id: 3,
Name: "PPE"
},
{
Id: 4,
Name: "01's"
}
]
}
];
$scope.Testing = [{
Id: 1,
"TestingTypeId": 1,
TestingType: "Functional Testing",
EnvironmentTypeId: 1,
EnvironmentType: "Dev/QE (VCD)",
value: 100
},
{
Id: 2,
"TestingTypeId": 3,
TestingType: "Integration",
EnvironmentTypeId: 1,
EnvironmentType: "Dev/QE (VCD)",
value: 98
}
];
$scope.loadData = function(entype, type) {
if ($scope.Testing !== undefined) {
angular.forEach($scope.Testing, function(item) {
if (item.TestingTypeId === type.Id && item.EnvironmentTypeId === entype.Id) {
return item.Value;
} else {
return initial;
}
});
}
};
}]);
有人能指出什么即时通讯做错误?
更新
这里是我的代码有plunker至今click
首先您询问如何从JSON使表的问题,现在你发布有关填充数据:/ –
我不能这样做呢?@WasifKhan – Shayuh
@Shayuh你可以做到这一点,但如果已经有解决方案,首先正确地谷歌问题是明智的。检查我的答案。 – umar