以下是我的一个js
var ruleField = [
{
id: "T1",
datastore: "",
table: "SENSORS",
columns: ["SNS_ID","HOST_ID","SESSION_ID"],
tableHeaders: ["SNS ID","HOST ID","SESSION ID"]
}
];
在另一个js我需要访问下拉选项中的列数组
<select name="child.KEY_NAME" ng-if="child.KEY_NAME != 'Host' && child.KEY_NAME != 'Sensor' && child.KEY_NAME != 'Operator' && child.KEY_NAME != 'Value'" class="form-control" ng-model="temp.condition[$index][child.KEY_NAME]"" ng-disabled="readonly" ng-change="selectedOption1(selectAction);displayActionParam()">
<option ng-repeat="field in ruleField.columns track by $index" value= "{{ field }}" >{{ field }}</option>
</select>
答案 0 :(得分:0)
您必须将var ruleField
分配给$scope
变量才能在角度指令中使用,只需添加以下行即可。
$scope.ruleField = angular.copy(ruleField);
将ng-repeat中的表达式更改为ng-repeat="field in ruleField[0].columns track by $index"
var app = angular.module('app',[]);
app.controller('Ctrl',function($scope,$filter){
var ruleField = [
{
id: "T1",
datastore: "",
table: "SENSORS",
columns: ["SNS_ID","HOST_ID","SESSION_ID"],
tableHeaders: ["SNS ID","HOST ID","SESSION ID"]
}
];
$scope.ruleField = angular.copy(ruleField);
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="Ctrl">
<select name="child.KEY_NAME" class="form-control" ng-model="temp.condition[$index][child.KEY_NAME]" ng-disabled="readonly" ng-change="selectedOption1(selectAction);displayActionParam()">
<option ng-repeat="field in ruleField[0].columns track by $index" value= "{{ field }}" >{{ field }}</option>
</select>
</div>
&#13;
答案 1 :(得分:0)
如果您添加第一个带有<script>
标记 BEFORE 的角色代码(指令,控制器等)的JS文件,ruleField
向量应该可以从任何脚本访问,正如@ Adrian Brand所说,你必须从它的索引访问数组,在这种情况下ruleField[0].columns
,一旦这些事情完成,你应该能够使用它并操纵它。