gpt4 book ai didi

javascript - 使用'select'元素在指令内包含自定义选项

转载 作者:行者123 更新时间:2023-11-29 19:08:44 24 4
gpt4 key购买 nike

我有一个有点通用的指令,该指令包含一个选择,该选择带有一组通过ajax加载(然后缓存)的选项。

事实是,我需要根据使用此指令的位置指定一些特定的选项。我当时想我可以排除这样的选择:

<select-directive ng-model="model">
<option value="x">custom option</option>
</select-directive>


指令为:

{
restrict: 'E',
scope:{
ngModel: '='
},
transclude:true,
template:[
'<select class="tipos" ng-model="ngModel">',
'<ng-transclude></ng-transclude>',
'<option ng-selected="ngModel === item.tipo" ng-repeat="item in ::tiposDoc track by item.tipo" value="{{::item.tipo}}" title="longer description">',
'description',
'</option>',
'</select>'
].join(''),
link: function(scope){
$http.get('viewApp/viewCtrl.php/getTipos',{cache:true})
.then(function(response){
var resp = response.data;
if(!resp.success){
console.log(resp.log);
alert(res.msg);
return false;
}
scope.tiposDoc = resp.result;
});
}
}


但是自定义选项不会显示在select元素中。我想念什么吗?这可能以某种方式出现吗?

最佳答案

您可以这样做:

link: function(scope, element, attrs, ctrls, transclude){
var html = transclude();
element.find('select').append(html);
}

关于javascript - 使用'select'元素在指令内包含自定义选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40808452/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com