我是新的是angularjs,我想在<script>
var styles = document.styleSheets[0].ownerNode;
var obj = JSON.parse(
styles.textContent
.match(/(\/\*{.*})(?=\*\/)/)[0]
.replace(/[/*]/g, "")
.trim()
);
console.log(obj["className"]["SomeProp"])
</script>
中获取索引值意味着我想将ng-repeat
值设置为索引值,我的代码是:
md-option
任何人都可以帮我这个吗?
答案 0 :(得分:6)
<md-input-container class="md-block" flex-gt-sm>
<label>Filterable Columns</label>
<md-select ng-model="visualization.filterable_columns" ng-change="drawFilters()" multiple="true">
<md-option ng-repeat="filterable_column in vm.filterable_columns" ng-value="{{$index}}">
{{filterable_column.label}}
</md-option>
</md-select>
</md-input-container>
答案 1 :(得分:3)
将追踪$ index 添加到 ng-repeat
<md-input-container class="md-block" flex-gt-sm>
<label>Filterable Columns</label>
<md-select ng-model="visualization.filterable_columns" ng-change="drawFilters()" multiple="true">
<md-option ng-repeat="filterable_column in vm.filterable_columns track by $index" ng-value="{{$index}}">
{{filterable_column.label}}
</md-option>
</md-select>
</md-input-container>
答案 2 :(得分:-1)
这是辅助函数;
$scope.getIndexOf=function(arr, val, prop) {
var l = arr.length,
k = 0;
for (k = 0; k < l; k = k + 1) {
if (arr[k][prop] === val) {
return k;
}
}
return false;
};
示例是;
$scope.Index=function(){
$scope.getIndexOf(vm.filterable_columns,"{{filterable_column.label}}","filterable_column.label")
};
您可以在md-option的ng-change事件中调用此函数。像这样;
<md-select ng-model="visualization.filterable_columns" ng-change="drawFilters(); getIndexOf(vm.filterable_columns, {{filterable_column.label}}, filterable_column.label) " multiple="true" ng-init="index = 1">
<md-option ng-repeat="filterable_column in vm.filterable_columns" value="{{index++}}">
{{filterable_column.label}}
</md-option>
</md-select>