2014-05-04 35 views
0
$scope.items.push({ 
"itemId": $scope.tabId + 1, 
"itemName" : itemName, 
}); 

我CONSOLE.LOG($ scope.itemId)每次將被推但它不會增加時間。標識增量前端邏輯

在每次推送後都可以使用$ http,但保持服務器亮起是很好的做法。如果對於一個不明確的字段,你不會在後端使用自動增量,你將如何處理這個問題?我的意思是最好的做法。

+0

你的榜樣一個的jsfiddle將有很大的幫助 – axelduch

回答

1

您的代碼將始終推送相同的ID(與您認識的相同),因爲您從不將增加的值分配給$scope.tabId

改變它的東西是這樣的:

function yourFunction() { 
    // increment $scope.tabId 
    $scope.tabId = $scope.tabId + 1 

    // push the new element to your array 
    $scope.items.push({ 
    "itemId": $scope.tabId, 
    "itemName": itemName 
    }); 
}