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