相关疑难解决方法(0)

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

如何在dropdown/ng-options中从加载的json中获取其他属性

在ng-change上我还想传递所选对象的campaignType.

我怎么能这样做?

我的观点看起来像这样

  <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>
Run Code Online (Sandbox Code Playgroud)

我的控制器看起来像这样

  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);

    }

}
Run Code Online (Sandbox Code Playgroud)

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

angularjs

14
推荐指数
2
解决办法
4万
查看次数

标签 统计

angularjs ×1