Mirror API自定义菜单和自定义属性 [英] Mirror API custom menu and custom properties

查看:105
本文介绍了Mirror API自定义菜单和自定义属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我已将自定义菜单项添加到用户时间轴项.我正在迭代中创建自定义菜单.有什么方法可以将自定义属性附加到自定义菜单项吗? ,这样我就知道单击了哪个菜单项.

ere是我的自定义菜单代码,

// And custom actions
List<MenuValue> menuValues = new ArrayList<MenuValue>();
menuValues.add(new MenuValue().setIconUrl(WebUtil.buildUrl(req, "/static/images/drill.png")).setDisplayName("Found"));
menuItemList.add(new MenuItem().setValues(menuValues).setId("found").setAction("CUSTOM"));

timelineItem.setMenuItems(menuItemList);
timelineItem.setNotification(new NotificationConfig().setLevel("DEFAULT"));

谢谢.

解决方案

您已经在使用setId()方法将属性附加到菜单项. Glass会忽略id中的值,但选择此菜单项时会将其发送回给您.您可以在此处放置任何您想要的东西(在合理的范围内-限制为几百个字符).

因此,在上面的示例中,如果选择了菜单项,则会收到如下所示的通知:

{ 
  "collection": "timeline",
  "itemId": "8a84302a-1da7-46f2-ac72-2c008fce2b4b",
  "operation": "UPDATE",
  "userToken": "12345678901234567890",
  "verifyToken": "shibboleet",
  "userActions": [ 
    { 
      "type": "CUSTOM", 
      "payload": "found" 
    }
  ]
}

您将检查userActions.payload字段并据此采取措施.

In my app I have added custom menu items to user timeline items. I am creating the custom menus in iteration. Is there any way to append the custom properties to the custom menu item? , so that I can know which menu item is clicked.

ere is my code for custom menu,

// And custom actions
List<MenuValue> menuValues = new ArrayList<MenuValue>();
menuValues.add(new MenuValue().setIconUrl(WebUtil.buildUrl(req, "/static/images/drill.png")).setDisplayName("Found"));
menuItemList.add(new MenuItem().setValues(menuValues).setId("found").setAction("CUSTOM"));

timelineItem.setMenuItems(menuItemList);
timelineItem.setNotification(new NotificationConfig().setLevel("DEFAULT"));

Thanks in advance.

解决方案

You're already attaching a property to the menu item with the setId() method. The value in the id is ignored by Glass except to send it back to you when this menu item is selected. You can put anything you want here (within reason - there is a limit of a few hundred characters).

So, given your example above, if the menu item is selected, you'd get a notification looking something like this:

{ 
  "collection": "timeline",
  "itemId": "8a84302a-1da7-46f2-ac72-2c008fce2b4b",
  "operation": "UPDATE",
  "userToken": "12345678901234567890",
  "verifyToken": "shibboleet",
  "userActions": [ 
    { 
      "type": "CUSTOM", 
      "payload": "found" 
    }
  ]
}

You would examine the userActions.payload field and take action based on this.

这篇关于Mirror API自定义菜单和自定义属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆