我對Angularjs非常陌生,我將列名(鍵值對中的鍵)綁定到了選擇列表並希望得到選擇變更選擇的關鍵名稱。 選擇清單顯示:如果下拉列表綁定了json的鍵,如何從下拉列表中選擇值
名稱,摘要和年齡
並選擇更改我想要的選擇選定的文本。請幫助 這裏是我的代碼:
<!DOCTYPE html>
<div ng-controller="HelloController">
<h2>Hello {{helloTo.title}} !</h2>
<select ng-options="key for (key,val) in phones[0]" ng-change="ChangeValue(key)" ng-model="phones"></select>
</div>
<script>
angular.module("myapp", [])
.controller("HelloController", function ($scope) {
$scope.helloTo = {};
$scope.helloTo.title = "World, AngularJS";
$scope.phones = [
{
'name': 'Nexus S',
'snippet': 'Fast just got faster with Nexus S.',
'age': 1
},
{
'name': 'Motorola XOOM™ with Wi-Fi',
'snippet': 'The Next, Next Generation tablet.',
'age': 2
},
{
'name': 'MOTOROLA XOOM™',
'snippet': 'The Next, Next Generation tablet.',
'age': 3
}
];
$scope.ChangeValue = function (selectedval) {
alert(selectedval.name);
};
});
</script>
即時通訊不是非常專業,但如果您控制選定的Val它輸出什麼? – ProllyGeek 2014-10-19 09:48:51
它返回undefined作爲值 – Gkhanna 2014-10-19 09:49:54
並提醒工作,我的意思是ChangeValue方法觸發? – ProllyGeek 2014-10-19 09:50:57