Javascript 从select ng options获取其他列
在指令中,我有以下内容:Javascript 从select ng options获取其他列,javascript,html,angularjs,angularjs-ng-options,Javascript,Html,Angularjs,Angularjs Ng Options,在指令中,我有以下内容: @String.Format(Labels.selectX、Labels.item) 是否希望在下拉列表中添加更多说明 <select data-ng-model="engineer.currentActivity" data-ng-options="a.name +' (' + a.type + ')' for a in activities"> 在控制器中: $scope.itemChanged = func
@String.Format(Labels.selectX、Labels.item)
是否希望在下拉列表中添加更多说明
<select data-ng-model="engineer.currentActivity"
data-ng-options="a.name +' (' + a.type + ')' for a in activities">
在控制器中:
$scope.itemChanged = function (itemId) {
var m = $scope.metaData.items;
var pos = $scope.metaData.items.map(function (e) { return e.itemId; }).indexOf(itemId);
var item = $scope.metaData.items[pos];
var descrip = item.descrip;
var departmentId = item.departmeId;
var categoryId = item.categoryId;
var department = item.department;
var category = item.category;
var theItem = item.item;
};
我只需要进一步澄清您需要从何处提取这些变量。如果您需要显示需要更改的其他列:
ng-options="c.itemId as c.descrip
致:
当您选择一个选项时,您的selectedItemId
模型将包含一个对象
然后可以使用ng change=“showItem(selectedItemId)”
显示其他值。其中selectedItemId
是当前对象
大概是这样的:
(函数(){
var-app=angular.module(“myApp”,[]);
app.controller(“controller”、[“$scope”,
职能($范围){
$scope.metaData={};
$scope.metaData.items=[{
“项目ID”:1,
“描述”:“一些描述”,
“离开”:1,
“类别”1,
“部门”:“部门1”,
“类别”:“A类”,
“项目”:“项目1。”
}, {
“项目ID”:2,
“描述”:“描述2…”,
“离开的人”:2,
“类别”1,
“部门”:“第二部门”,
“类别”:“B类”,
“项目”:“项目2…”
}];
$scope.showItem=功能(项目){
$scope.descripp=item.descripp;
$scope.departmeId=item.departmeId;
$scope.categoryId=item.categoryId;
$scope.department=item.department;
$scope.category=item.category;
$scope.item=item.item;
};
}
]);
})();代码>
描述:{{descrip}}
departmeId:{{departmeId}
类别:{{category}
部门:{{department}
departmeId:{{departmeId}
项目:{{item}
是的,我也决定走这条路线。我在开车的时候想了想,经过了我需要转弯的地方:)不管怎样,我已经决定完全按照你发布的那样做,你刚刚确认了。有一些问题。我无法使项目最初显示。其次,当我试图显示索引页中的另一行时,指令代码会在检索数据之前触发。这里是输出(第一次和第二次):检索到的当前卡活动数据。。smDci.js:29 Selected departmentId=0 Selected categoryId=0 Selected ItemId=300 smDci.js:42个初始选项即将启动。。。smDci.js:29 Selected departmentId=0 Selected categoryId=0 Selected ItemId=0 CardActController.js:223检索到的当前卡活动数据..请用这些代码更新您的问题好吗?记住,现在您有了ng选项=“c作为c.descripp
。请参阅我的另一个问题-我解决了这两个问题-首先使用手表,第二次遍历数组并重新初始化变量。请参阅重新阅读此问题,因为我需要解决类似的问题。我有带Id、说明和等代码的国家列表。有没有一种简单的方法可以在不改变整个内容的情况下获取所选项目的等码?可能只是添加一个函数,使用数组中的find方法通过Id获取代码(来自lodash)
ng-options="c.itemId as c.descrip
ng-options="c as c.descrip