从工厂(AJAX) API填充的视图中有下拉列表,换句话说,我有一个JSON格式的数据来填充dropdown(id,display_text),如下所示:
My View
<select class="form-control padding-7" ng-model="selConnData.repeatSelect" ng-options="types.id as types.text for types in selConnData.connList" ng-change="updateConType('{{types.val}}')">
</select>我的控制器
$scope.selConnData = {
repeatSelect: null
};
getConnectionList.connectionList().then(function(response){
console.log(JSON.stringify(response.data));
var tempConnections = {};
var tempConnList = [];
angular.forEach(response.data.result, function(value, key) {
tempConnList.push({
id: value.Id,
text: value.Name,
val: "thrLoc"
});
});
$scope.selConnData.connList = tempConnList;
});我的工厂
app.factory('getConnectionList', function($http) {
var resultant = {};
resultant.connectionList = function(){
return $http({
method: 'GET',
url: "xyz"
});
}
return resultant;
});我的最后一个JSON o/p将出现在:
[{
id: 1,
text: "Connection 1",
val: "8010"
},{
id: 2,
text: "Connection 3",
val: "8030"
},{
id: 9,
text: "Connection 4",
val: "8040"
}]现在,我的下拉选项就像
<select>
<option value="1">Connection 1</option>
<option value="2">Connection 3</option>
<option value="9">Connection 4</option>
</select>到这里为止,一切都在工作,我的ng模型给了我选定的值,但我需要一个条件来运行,在改变选项时,我将检查(8010)做什么--如果(8030)做其他的事情--如果(8040)做--做什么--做什么。
P.S:我试过了ng-attr,但不是最好的例子(不能把值拿出来)。
发布于 2015-11-06 12:02:48
如果你想要id和value,那么你可以尝试这样的方法,
<select class="form-control padding-7" ng-model="select" ng-options="{id:types.id,val:types.val} as types.text for types in options" ng-change="updateConType(select)">
</select>柱塞链接。
https://stackoverflow.com/questions/33553131
复制相似问题