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