选择ng-option时更新控制器变量

时间:2016-08-03 18:38:24

标签: angularjs

我正在尝试在控制器中设置一个变量,而另一个值是通过def method_3(): mat = gen_fake_data() x = np.unique(mat[:,0]) y = np.unique(mat[:,1]) X,Y = np.meshgrid(x, y) # I'm fairly sure there's a more efficient way of doing this... def get_z(mat, x, y): ind = (mat[:,(0,1)] == (x,y)).all(axis=1) row = mat[ind,:] return row[0,2] z = np.array([get_z(mat,x,y) for (x,y) in zip(np.ravel(X), np.ravel(Y))]) Z = z.reshape(X.shape) plt.pcolormesh(X,Y,Z) plt.xlim(min(x), max(x)) plt.ylim(min(y), max(y)) plt.show() 选择的。例如,如果根据ng-optionsCompanies中选择一个,那么title将被设置为特定公司的相应myValue。以下是HTML代码段:

id

我的<select multiple="" class="form-control" ng-model="myValue" ng-options="d.title for d in Companies"></select> <select multiple="" class="form-control"> <option ng-placeholder="{{myValue}}"></option> </select> CompanyCompanies在控制器中:

myValue

以下是function Company(title, last, pw, id) { this.title = title; this.id = id; } $scope.Companies = []; $scope.myValue = ''; 数组的种子:

Companies

该程序背后的目的是根据所选的$scope.getValues = function () { $http.get('/route/to/names') .success(function (data, status, headers, config) { for (var i = 0; i < data.length; i++) { $scope.Companies.push(new Company(data[i]['Title'],data[i]['ID'])); } }) }; 进一步从数据库中获取数据。我在页面上设置Company作为选项的原因是确定是否实现了操作。任何关于如何解决这个或类似问题的建议将不胜感激!谢谢!

1 个答案:

答案 0 :(得分:0)

d.id as d.title for d in Companies 
  • 请确保使用正确的大小写,因为您的公司构造函数中的标题和标识为小写,但在for循环中已正确套装