gpt4 book ai didi

angularjs - 在 ng-change 上传递所选对象的其他属性

转载 作者:行者123 更新时间:2023-12-03 21:15:41 27 4
gpt4 key购买 nike

如何从下拉列表/ng-options 中加载的 json 中获取其他属性

在 ng-change 中,我也喜欢传递所选对象的事件类型。

我怎么能做到这一点?

我的观点是这样的

  <div ng-app>
<div ng-controller="cCtrl">
<select ng-model="campaign" ng-options="c.id as c.name for c in campaigns" ng-change="search2(c.campaignType)">
<option value="">-- choose campaign --</option>
</select>
</div>
</div>

我的 Controller 看起来像这样
  function cCtrl($scope) {

$scope.campaigns = [{
"custID": 1,
"custName": "aaa ",
"msgID": 3,
"msgName": "Email Test Msg",
"id": 2,
"name": "Email Test Campaign",
"description": "Test Campaign",
"campaignType": "Email",
"created": "1374229715",
"isActive": 1,
"isDeleted": 0
}];

$scope.search2 = function (campaignType) {
alert(campaignType); // not working
alert($scope.campaign.campaignType); // not working
//console.log($scope.campaign.campaignType);

}

}

http://jsfiddle.net/webtheveloper/Qgmz7/8/

最佳答案

您可以像这样将选定的对象传递到函数中,而不是传递属性

<select ng-model="campaign" ng-options="c.name for c in campaigns" ng-change="search2(campaign)">

Working Demo

关于angularjs - 在 ng-change 上传递所选对象的其他属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18640370/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com