0
這是我的HTML在選擇控制的服務器,並使用NG選項獲取數據未能顯示選項
<div ng-app="timeTable" ng-controller="addCoursesCtrl">
<button class="btn btn-primary" ng-click="addNewCourse()">Add New Course</button><br/><br/>
<fieldset ng-repeat="choice in choices">
<div class="row">
<div class="col-md-6">
<select class="form-control" ng-model="choice.type" ng-options="s for s in coursetoAdd">
<option value="{{s.shortCut}}">{{s.name}}</option>
</select>
</div>
<div class="col-md-6">
<input type="text" placeholder="Enter Course Name" name="" class="form-control" ng-model="choice.course"/>
</div>
</div>
<br/>
</fieldset>
<button class="btn btn-primary" ng-click="convertAndSend()">Submit</button>
</div>
這個JS
var timeTable = angular.module("timeTable",[]);
timeTable.controller("addCoursesCtrl", function ($scope,$http) {
$scope.choices = [{ course: '', type: '' }];
$scope.coursetoAdd ;
$http.get("/Semster/getSuggtedCourses").then(function (response) {
$scope.coursetoAdd = response.data;
});
$scope.addNewCourse = function() {
var newITemNo = $scope.choices.length + 1;
$scope.choices.push({ course: '', type: '' });
};
$scope.convertAndSend = function() {
var asJson = angular.toJson($scope.choices);
console.log(asJson);
$http.post('/Semster/Add', asJson);
};
});
此代碼綁定對象{「當然」 :...,「type」:....}每次你點擊添加課程,並動態添加輸入字段,我的問題是選擇控制,我從服務器獲取數據並將其與ng-optin一起使用,但它顯示的只是選擇選項中的[對象對象]而非實際值。
get方法返回JSON數據,但這僅適用於s.name,我需要綁定不同於成分 – 2015-04-04 20:35:15
更有甚返回的JSON的結構? – tophatsteve 2015-04-05 09:32:53