0
我需要選擇的國家名進入鍵名country
,但$scope.options
將不被認可。我無法選擇國家,更不用說將正確的國家轉變爲關鍵價值。所以有人知道我做錯了什麼,以及在這種情況下可能的解決方案。NG選項需要爲對象值傳遞給數組
任何一個知道如何才能解決這個問題?
\t $scope.addComment = function() {
\t \t $scope.comments.push($scope.dataObject);
\t \t $scope.options = [{
\t \t \t id: 1,
\t \t \t country: "China"
\t \t \t },
\t \t \t {
\t \t \t id: 2,
\t \t \t country: "France"
\t \t \t },
\t \t \t {
\t \t \t id: 3,
\t \t \t country: "Germany"
\t \t \t },
\t \t \t {
\t \t \t id: 4,
\t \t \t country: "Japan"
\t \t \t },
\t \t \t {
\t \t \t id: 5,
\t \t \t country: "Hongary"
\t \t \t },
\t \t \t {
\t \t \t id: 6,
\t \t \t country: "Hong Kong"
\t \t \t },
\t \t \t {
\t \t \t id: 7,
\t \t \t countrybv : "Italy"
\t \t \t }]
\t \t $scope.dataObject = {
\t \t \t name: "",
\t \t \t country: $scope.options[0],
\t \t \t comment: ""
\t \t };
\t };
<body>
<td><select class="comment-form comment" ng-model="selected" ng-options="option as option.country for option in options track by option.id">
<option value="">Select a country</option>
</select></td>
</body>
問題是$ scope.options不會被識別.... –
「track by x.Id」應該是「track by x.id」 – jbrown
我知道,已經閱讀過文檔,但它無法鏈接到ID。這是這樣做的主要問題....也許我忽視了JavaScript的部分東西... –