我试图弄清楚如何摆脱下拉菜单中显示的空白区域。菜单中没有“全部”选项。我放弃了该选项(可能不是正确的选择),有时刷新时我可以看到菜单,并且有空白,而有时它只是在控制台上给我一个错误。我不确定为什么存在这种多样性。
最终,我必须摆脱All选项(以正确的方式)并删除它留下的空白。
这是我的js:
define(["app",
"lodash",
"service/reference",
"directives/control/topic-input"
], function (app) {
return app.directive('roleSelect', ['Reference', function (Reference) {
return {
restrict: 'A',
scope: {
selectedRole: '=',
selectedTopics: '=?',
presetRole: '=?',
topicNameOnly: '@?',
notUsePresets:'@?'
},
link: function ($scope, elem, attr) {
$scope.talentRoles = [];
$scope.topicNameOnly = ($scope.topicNameOnly === 'true');
$scope.notUsePresets = ($scope.notUsePresets === 'true');
if(!$scope.presetRole) {
$scope.presetRole = {id: -1, code: "ALL", description: "All"};
} // this is where the 'All' option comes from, so I just got rid of this if statement. Not sure if this is the right thing to do
if(!$scope.notUsePresets) {
$scope.talentRoles.push($scope.presetRole);
}
Reference.getTalentRoles($scope, function (response) {
$scope.talentRoles = response.concat($scope.talentRoles);
for(var i = 0;i<$scope.talentRoles.length;i++){
if($scope.selectedRole && $scope.selectedRole.description == $scope.talentRoles[i].description){
$scope.selectedRole = $scope.talentRoles[i];
}
}
});
$scope.showTopics = function(){
return attr.selectedTopics
}
$scope.roleChanged = function(role) {
$scope.selectedTopics = [];
};
},
templateUrl: '/directives/control/role-select.html'
};
}])
});
这是我的html:
<select class="form-control" required
id="roleSelector"
ng-options="talentRole as talentRole.description for talentRole in talentRoles track by talentRole.id" id="talentRole"
ng-change="roleChanged(role)"
ng-model="selectedRole">
<option ng-if="true" selected="true" value="" class="select-placeholder"><ln code="directive.role.select.tooltip" args=""></ln></option>
</select>
<div topic-input
name-only="topicNameOnly"
class="row-spacing"
ng-show="showTopics()"
ng-model="selectedTopics"
talent-role-id="selectedRole.id"></div>
我不太喜欢有角的JS / html。但是,我确实知道该<option>
</option>
标记可确保从用户端选择的任何内容都保持在我这一边(作为管理员)。因此,该功能需要保留。我也了解ng-options是此菜单的母亲。因此,可能需要使用此标签进行一些配置。
这是从JavaScript删除if语句之前的快照:
看来,当我删除if语句时,我在控制台上收到此错误:
TypeError:无法读取未定义的属性“描述”
因此,我猜想摆脱这种状况不是正确的选择。如果我给的不够多,我深表歉意,但是请让我知道我能做些什么来帮助您进一步帮助我,我将非常高兴提供住宿。
我认为如果删除presetRole: '=?'
,您也应该从$ scope初始化中删除if
。
另外,您还需要检查是否有任何其他对的引用presetRole
,因为即使您删除了if
,它presetRole
也仍然会添加到中talentRoles
。
告诉我是否有效。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句