Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 在Ionic 2中动态设置操作表的选项_Angularjs_Angular_Ionic Framework - Fatal编程技术网

Angularjs 在Ionic 2中动态设置操作表的选项

Angularjs 在Ionic 2中动态设置操作表的选项,angularjs,angular,ionic-framework,Angularjs,Angular,Ionic Framework,我正在发出一个GET请求,以获取一些包含选项数组的JSON。在每个元素中,我都有一个id、样式和名称 根据响应,我想在Ionic 2应用程序中动态设置我的操作表选项 这张行动单很好用。我的挑战是根据API响应动态设置选项 let actionSheet = this.actionSheetCtrl.create({ title: 'Change the tag of this visitor', buttons: [ { text: 'Destructive red',

我正在发出一个GET请求,以获取一些包含选项数组的JSON。在每个元素中,我都有一个id、样式和名称

根据响应,我想在Ionic 2应用程序中动态设置我的操作表选项

这张行动单很好用。我的挑战是根据API响应动态设置选项

let actionSheet = this.actionSheetCtrl.create({
 title: 'Change the tag of this visitor',
 buttons: [
   {
     text: 'Destructive red',
     cssClass: 'label-red',
     handler: () => {
       myFunction(1);
     }
   },
   {
     text: 'Archive blue',
     cssClass: 'label-dark-blue',
     handler: () => {
       myFunction(2);
     }
   },
   {
     text: 'Cancel',
     role: 'cancel',
     handler: () => {
       console.log('Cancel clicked');
     }
   }
 ]
});
我希望保留取消选项,但在上面显示我自己的选项,即删除破坏性选项和存档选项

在PHP中,我将使用以下伪代码实现这一点

$options = array();
$options['title'] = 'Change the tag of this visitor';

$buttons = array();

foreach($api_response as $a) {
    array_push($buttons, array('text' => $a['name'], 'cssClass' => $a['style']) );
}

$options['buttons'] = $buttons;

let actionSheet = this.actionSheetCtrl.create(json_encode($options));
然后我的最后一个问题是,我如何从循环的元素中指定适当的id值作为myFunction()调用的参数。。。e、 g当id=1时,将XX的值设置为1;当id=20时,将XX的值设置为20,以此类推

e、 g


我似乎找到了更好的办法来解决这个问题。我正在使用addButton方法

let actionSheet = this.actionSheetCtrl.create({
    title: 'Change the tag of this visitor'
});    

this.http.get('http://api.domain.com/tags', {headers:headers}).map(res => res.json()).subscribe(data => {
    for (var i = 0; i < data.res.length; i++) {
        actionSheet.addButton({text: data.res[i].name, cssClass: data.res[i].style });        
    }
}); 

actionSheet.addButton({text: 'Cancel', 'role': 'cancel' });       

actionSheet.present();  
let actionSheet=this.actionSheetCtrl.create({
标题:“更改此访问者的标签”
});    
this.http.get('http://api.domain.com/tags“,{headers:headers}).map(res=>res.json()).subscribe(data=>{
对于(var i=0;i
如何管理操作表中每个按钮触发的功能?您好。像这样<代码>actionSheet.addButton({text:'Go to dashboard',handler:()=>{this.navCtrl.setRoot(ListTeamsPage);}})根据数组中的元素触发处理程序如何。根据您的示例,如何使click事件依赖于data.res[I].index(假设每个迭代的索引都是唯一的)值。
let actionSheet = this.actionSheetCtrl.create({
    title: 'Change the tag of this visitor'
});    

this.http.get('http://api.domain.com/tags', {headers:headers}).map(res => res.json()).subscribe(data => {
    for (var i = 0; i < data.res.length; i++) {
        actionSheet.addButton({text: data.res[i].name, cssClass: data.res[i].style });        
    }
}); 

actionSheet.addButton({text: 'Cancel', 'role': 'cancel' });       

actionSheet.present();