我正在尝试通过 firebase 向我的设备发送消息。但我得到了错误。我在高级 REST 客户端上成功测试了它。这是来自休息客户端的消息
Content-Type: application/json
Authorization: key=MY-KEY
Content-Length: 106
POST /fcm/send HTTP/1.1
HOST: fcm.googleapis.com
content-type: application/json
authorization: key=MY-KEY
content-length: 106
{
"to":"/topics/Self_Taught"
"notification":
{
"body":"Hello"
}
}
Run Code Online (Sandbox Code Playgroud)
基于此,我制作了我的 javascript 代码。不用担心gritter,它是其他库,并且可以正常工作。
$.ajax({
url: "https://fcm.googleapis.com/fcm/send",
type: "POST",
contentType: "application/json",
authorization: "key=MY-KEY",
data: {
"to": "/topics/Self_Taught",
"notification": {
"body": message
}
},
success: function (result) {
$.gritter.add({
title: "",
text: result.message_id,
class_name: 'gritter-success'
});
},
error: function (result) {
$.gritter.add({
title: "",
text: result.error,
class_name: 'gritter-error'
});
}
});
Run Code Online (Sandbox Code Playgroud)
这就是我从 result.error …
我有一个这样的文本:用户 ID: 12345
我只想把它放在一个文本标签中。<Text>UserID: 12345</Text>
但如果我这样做,两部分都会是相同的风格。那么我们可以只将“UserID”设为粗体吗?
我有一个像这样荒谬的对象.
{
order: ["a1","a2","a3","a4"],
posts: {
a1: {id: "a1",message: "This is a1"},
a4: {id: "a4",message: "This is a4"},
a3: {id: "a3",message: "This is a3"},
a2: {id: "a2",message: "This is a2"},
}
}
Run Code Online (Sandbox Code Playgroud)
我需要从"posts"对象获取"message"值,其顺序为"order"数组中定义的顺序.我可以预先处理"order"数组,但是如何知道我什么时候有"a1"字符串,我需要在"posts"对象中取"a1"对象?
谢谢!