0
我做了大量的研究,但我没有找到答案,或者我不明白有人写的代码 - 它不工作。现在我有很多代码。我想用AngularJS优化我的代码 - 例如ng-repeat
或类似的东西。例子是,如果线..并有4个...我怎样才能优化我的代码与angularjs
$scope.url = "an URL";
$http.get($scope.url)
.then(function(response) {
$scope.x = response.data;
var y1 = response.data.a.tools;
var y2 = response.data.b.tools;
var y3 = response.data.c.tools;
var y4 = response.data.d.tools;
var y5 = response.data.e.tools;
var y6 = response.data.f.tools;
//...
var boxArray = ["jenkins", "gitHub", "jira", "urbanCode"];
if (y1[0] == boxArray[0]) {$scope.jenkins1 = boxArray[0];} else {$scope.jenkins1 ="";};
if (y1[1] == boxArray[1]) {$scope.gitHub1 = boxArray[1];} else {$scope.gitHub1 ="";};
if (y1[2] == boxArray[2]) {$scope.jira1 = boxArray[2];} else {$scope.jira1 ="";};
if (y1[3] == boxArray[3]) {$scope.urbanCode1 = boxArray[3];} else {$scope.urbanCode1 ="";};
if (y2[0] == boxArray[0]) {$scope.jenkins2 = boxArray[0];} else {$scope.jenkins2 ="";};
if (y2[1] == boxArray[1]) {$scope.gitHub2 = boxArray[1];} else {$scope.gitHub2 ="";};
if (y2[2] == boxArray[2]) {$scope.jira2 = boxArray[2];} else {$scope.jira2 ="";};
if (y2[3] == boxArray[3]) {$scope.urbanCode2 = boxArray[3];} else {$scope.urbanCode2 ="";};
//.....
我想从boxArray
我复选框,而不是真或假获取名称后面。
请发布一些json数据,你从http调用和格式化你的代码 –
询问“如何优化”可能太宽泛。你能缩小到更具体的东西吗? – Robert
是的,抱歉,问题是广泛的。我刚开始,那就是为什么我不知道哪个特定的代码对你很重要。下次我会给你更多的细节。 georgeawg的回答很有帮助,谢谢! – Leinadapp