1.我有了一個集合稱爲與以下標記AxleTypes一個卡車類:AngularJS加入2個屬性相關聯的集合
public class AxleType : Entity
{
public string Description { get; set; }
public string Type { get; set; }
}
2.我的角形式包括以下(以保持此儘可能短我省略形式的其他橋型,和我使用的$父,因爲這是一個模板,並在主要形式通NG-包括):
<label for="frontAxles">Front Axle: </label>
<input ng-model="$parent.frontAxleType" type="hidden" value="Front">
<select ng-model="$parent.selectedFrontAxle" ng-options="axleType.Description for axleType in axleTypes">
<option value="" selected>Select Axle Type ..</option>
</select>
3.主要形式插入通過卡車控制器新的卡車,因此在卡車控制器:
a. I instantiate an instance of the AxleTypes collection so the form is populates the select w/axle types.
b. I instantiate an instance of AxleType to pass the selected data from the form.
c. I pass the respective ng-models on the form to the AxleType variable.
d. I add that AxleType variable to the Truck's AxleTypes collection.
a: if ($scope.axleTypes == undefined || !($scope.axleTypes.length > 0))
{ $scope.axleTypes = API.GetAxleTypes(); }
b: $scope.axleType = {};
c: var frontAxle = $scope.axleType;
frontAxle.Description = $scope.selectedFrontAxle;
frontAxle.Type = $scope.frontAxleType;
d: newTruck.AxleTypes = [
angular.copy(frontAxle)
];
當調試這是最終結果是:
爲了保持這儘可能短我沒有說明第二軸類型選擇上面。但是,正如您所看到的,服務器正在拾取2個軸類型,但是每個[類型&描述]的屬性均爲空。 有沒有人有任何建議?
在console.log中,這兩個值都是「undefined」。
一個有趣的現象:
當我硬編碼在TruckCtrl價值觀,一切工作正常:
frontAxle.Description = 'Some Front Value';
frontAxle.Type = 'Front';
rearAxle.Description = 'Some Rear Value';
rearAxle.Type = 'Rear';
newTruck.AxleTypes = [
angular.copy(frontAxle),
angular.copy(rearAxle)
];
這將導致有人認爲問題出在NG-模型在軸模板上。然而,當我只有一個屬性,就是說明,而不是鍵入服務器類,AxleType,並通過只是增加了選擇的描述:
newTruck.AxleTypes = [
angular.copy($scope.selectedFrontAxle),
angular.copy($scope.selectedRearAxle)
];
傳遞的價值觀。很混亂。
這與angularjs有什麼關係?從我看到的調試截圖是從C#(?)? – 2013-03-14 18:56:28
我沒有看到,對不起。好的,你如何將數據發送到服務器?你在使用$資源服務嗎?或$ http? – 2013-03-14 19:03:10