<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>forEach的用法</title>
</head>
<body>
<table border="" cellspacing="" cellpadding="">
<thead>
<tr><th>Key</th></tr>
<tr><th>Value</th></tr>
<tr><th>Header</th></tr>
</thead>
<tbody>
<tr ng-repeat="map in configMapEdit.newConfigMap.data">
<td>
<input type="text" ng-model="map.key" ng-blur="configMapEdit.checkKey(map.key)" placeholder="必填" maxlength="255" />
</td>
<td>
<input type="text" ng-model="map.val" />
</td>
<td>
<a ng-click="configMapEdit.delDataMap($index)">
<i class='fa fa-trash-o'></i>
</td>
</tr>
<tr>
<button ng-click="congfigMapEdit.addDataMap()">增加数据</button>
</tr>
</tbody>
</table>
</body>
<script>
//configMapEdit.configMapInfo.data={text2.txt:"12313",text3.txt:"4545"}-->configMapEdit.data=[{key:"text2.txt",val:"12313"},{key:"text3.txt",val:"4545"}]
configMapEdit.data=[];
Object.keys(configMapEdit.configMapInfo.data).forEach(function(key){configMapEdit.data.push(key:key,val:configMapEdit.configMapInfo.data[key])})
function updateConfigMapOnClick(){
var sendParams={
namespace:'',
name:'',
data:{}
};
sendParams.namespace=configMapEdit.newConfigMap.namespace;
sendParams.name=configMapEdit.newConfigMap.name;
if(configMapEdit.configType.value==='data'){
if(configMapEdit.newConfigMap.data.length==0){
$scope.alert("请输入配置";)
return;
}
sendParams.data={};
var keysTemp=[];
var isBreak=false;
configMapEdit.newConfigMap.data.forEach(function(map,index){
if(map.key==null||map.key==''){
$scope.alert("配置数据key 不能为空!");
isBreak=true;
return;
}
if(map.val==null||map.val==""){
$scope.alert("配置数据value 不能为空!");
isBreak=true;
return;
}
var reg=new RegExp("^[-._a-zA-Z0-9]{1,255}$");
if(!reg.test(map.key)){
$scope.alert("配置的数据key 请仅包含字母、数字、点号、下划线、横线");
isBreak=true;
return;
}
if(!reg.test(map.val)){
$scope.alert("配置的数据value 请仅包含字母、数字、点号、下划线、横线");
isBreak=true;
return;
}
if(keysTemp.indexOf(map.key)>=0){
$scope.alert("配置的数据key不能重复");
isBreak=true;
return;
}
keysTemp.push(map.key);
sendParams.data[map.key]=map.val;
});
if(isBreak){return}
configmapService.updateConfigMap(sendParams).then(function(){
$scope.alert("编辑成功");
$scope.State.go("configMap");
},function(){
$scope.alert("Error");
})
}else{
if(configMapEdit.oldFileClolse){
uploadFile(sendParams.namespace,sendParams.name);
}else{
$scope.alert("n您没有上传,请重新操作或返回退出")
}
}
}
</script>
</html>
//map的用法,处理其中的某一项
onConfirm:function(selectedItems){
if(selectedItems.length!=0){
helmDeploymentCreate.chartsInfo=selectedItems;
helmDeploymentCreate.chartsInfo.map(function(item){
item.description='';
return item;
});
helmDeploymentCreate.resgName=helmDeploymentCreate.chartsInfo[0].resgName;
}
helmDeploymentCreate.charOptions.display=false;
}
function changeCluster(index){
helmDeploymentCreate.chartsInfo[index].zone=helmDeploymentCreate.chartsInfo[index].clusterInfo.zone;
helmDeploymentCreate.chartsInfo[index].namespace=helmDeploymentCreate.chartsInfo[index].clusterInfo.namespace;
helmDeploymentCreate.chartsInfo[index].clusterName=helmDeploymentCreate.chartsInfo[index].clusterInfo.clusterName;
helmDeploymentCreate.checkReleaseNumber(helmDeploymentCreate.chartsInfo[index].namespace);//change事件的时候调用验证的接口返回信息,
}
helmDeploymentCreate.checkReleaseNumber=function(namespace){//核对部署的资源限制信息(验证数量的接口)
var params={
namespace:namespace
};
return helmDeploymentService.checkReleaseNumber(params).then(function(res){
if(res.pods.remainder<100){
helmDeploymentCreate.disable=false;
helmDeploymentCreate.limitTip="* 该集群下pod最多可部署"+res.pods.remainder+"个,如有特殊需求,请联系管理员";
helmDeploymentCreate.chartsInfo.map(function(item){
if(item.namespace==namespace){
item.description=helmDeploymentCreate.limitTip;
}
return item;
})
}else{
helmDeploymentCreate.limitTip='';
return helmDeploymentCreate.limitTip;
}
})
}