如何将选定的ID从kendo组合框传递给角度函数

时间:2015-05-15 13:41:19

标签: angularjs kendo-ui

我正在使用桌子和桌子身体是ng-repeat。我想通过kendo组合框传递所选项目的ID,但它总是将最后一项ID传递给该函数。

   <tbody>
            <tr ng-repeat="hours in GetHours">
                <td style="width:2%"><input type="checkbox" ng-model="hours.Selected" ng-change="RefreshSelectedDealsCount()" /></td>
                <td style="width:25%;text-align:left">{{hours.ContactName}}</td>
                <td style="width:25%;text-align:left">{{hours.Hours}}</td>
                <td style="width:20%;text-align:left"><select id="combobox" kendo-combo-box class="form-control" k-ng-model="hours.DealName" 
            ng-click="GetDeals(hours)" k-options="myDealList" style="width: 190px" k-placeholder="'Select deal'"></select></td>
            </tr>
    </tbody>

//在JS控制器中 - &gt;

 //Get All the Deals Related to contacts
    $scope.GetDeals = function (hours) 
    {
        $scope.CurrentHour = hours;
    }

// For Kendo Combo box in JS Controller

$scope.DealDataSource = {
    serverFiltering: true,
    transport: {
        read: {
            dataType: "json",
            url: '/Project/GetContactDeals',
            data: {

                id: function () {
                    return $scope.CurrentHour.FKContactID;
                },
            },
        }
    }
};
$scope.myDealList = {
    dataSource: $scope.DealDataSource,
    dataTextField: "Todeal",
    delay: 300,
    autoBind:false,
    highlightFirst: true,
    select: function (ev) {
        $scope.DelID = 0;
        var dealID = this.dataItem(ev.item.index()).Dealid;
        $scope.DelID = dealID;
        $scope.CurrentHour.DealID = dealID
    },
}

1 个答案:

答案 0 :(得分:2)

您可以尝试使用此代码,我认为它可以帮助您

<td style="width:20%;text-align:left"><select kendo-combo-box k-data-text-field="'Subject'" k-data-value-field="'DealID'" k-ng-model="hoursSelectedDeal" k-on-change="getSelectedContact(hoursSelectedDeal,kendoEvent)" k-data-source="hours.DealList" style="width: 190px" k-placeholder="'Select deal'"></select></td>

 $scope.getSelectedContact = function (item,e) {
    console.log(e.sender.$angular_scope.this.hours);
    for (var i = 0; i < $scope.GetHours.length; i++) {
        for (var j = 0; j < $scope.GetHours[i].DealList.length; j++) {

            if ($scope.GetHours[i].DealList[j].DealID == item) {

                $scope.selectedRow.DealID = $scope.GetHours[i].DealList[j].DealID;
                $scope.selectedRow.DealName = $scope.GetHours[i].DealList[j].Subject;
                $scope.selectedRow.ContactID = $scope.GetHours[i].FKContactID;
            }
            else
            {
                $scope.selectedRow.DealID = 0;
                $scope.selectedRow.DealName = e.sender.$angular_scope.hoursSelectedDeal;
                $scope.selectedRow.ContactID = e.sender.$angular_scope.this.hours.FKContactID;
            }
        }
    }
    var index = -1;
    for (var k = 0; k < $scope.AllSelectedContacts.length; k++) {
        if ($scope.AllSelectedContacts[k].ContactID == $scope.selectedRow.ContactID) {
            if( $scope.AllSelectedContacts[k].DealID == $scope.selectedRow.DealID)
            {
                index = 1;
                $scope.AllSelectedContacts.splice(k);
            }
            else
            {
                index = 1;
                $scope.AllSelectedContacts[k].DealID = $scope.selectedRow.DealID;
                $scope.AllSelectedContacts[k].DealName = $scope.selectedRow.DealName;
            }

        }


    }

    if (index == -1) {
        $scope.AllSelectedContacts.push({
            DealID: $scope.selectedRow.DealID,
            DealName: $scope.selectedRow.DealName,
            ContactID: $scope.selectedRow.ContactID
        });
    }

    console.log($scope.selectedRow);

}