gpt4 book ai didi

angularjs - 如何将选定的ID从kendo组合框传递到 Angular 函数

转载 作者:行者123 更新时间:2023-12-02 12:38:19 24 4
gpt4 key购买 nike

我正在使用一个表格,并且表格主体处于 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 Controller 中->

 //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
},
}

最佳答案

你可以尝试使用这段代码,我认为它对你有帮助

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

}

关于angularjs - 如何将选定的ID从kendo组合框传递到 Angular 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30261001/

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