gpt4 book ai didi

javascript - Pebble JS、GitHub 和图像资源

转载 作者:数据小太阳 更新时间:2023-10-29 05:35:54 25 4
gpt4 key购买 nike

我正在开发一个从 GitHub 存储库加载的 pebble.js 项目。我基本上是在本地编写我的代码,推送到 GitHub,然后拉入 CloudPebble 进行构建,因为我的计算机不适合运行 SDK。 CloudPebble 可以正确查看我的图像资源,但我不知道如何引用它。最初,它找不到图像,直到我将子路径移到 resources 文件夹中。这允许正确导入,但每当我引用我的图像时,我都会在应用程序日志中得到这个:

JavaScript Error:
send@[native code]
at load (ui/windowstack.js:2654:22)
at load (lib/image.js:165:11)
at load (ui/imageservice.js:85:16)
at resolve (ui/imageservice.js:109:60)
at ImageType (ui/simply-pebble.js:41:32)
at lib/struct.js:161:32
at menuItem (ui/simply-pebble.js:814:10)
at _resolveItem (ui/menu.js:161:30)
at _preloadItems (ui/menu.js:170:22)
at _resolveSection (ui/menu.js:151:25)
at section (ui/menu.js:239:23)
at updateActivityMenu (app.js:44:18)
at app.js:167:21
at onreadystatechange (lib/ajax.js:109:17)

这是我的项目结构示例:

/project/resources/images/some_image.png
/project/src/app.js
/project/appinfo.json

这是 appinfo.js 的相关部分

    "media": [
{
"file": "images/some_image.png",
"name": "MY_IMAGE",
"type": "png"
}
]

最后是来自 app.js

的相关部分
    var item = {
title: data.Response.data.activity.activityName,
subtitle: data.Response.data.activity.activityDescription,
icon: 'MY_IMAGE'
};

我也曾尝试直接引用 icon 属性的图像路径,但图像从未显示,我得到了相同的 JavaScript 错误。我可以在构建日志中看到正确添加的图像:

[ 6/29] some_image.png.pbi: resources/images/some_image.png ../../app/sdk2/Pebble/tools/bitmapgen.py -> build/resources/images/some_image.png.pbi

此时我不知所措 - 任何帮助将不胜感激。

最佳答案

尝试使用图像的路径而不是其资源 ID:

var item = {
title: data.Response.data.activity.activityName,
subtitle: data.Response.data.activity.activityDescription,
icon: 'images/some_image.png'
};

pebble.js 文档 suggests that this is the proper approach for internal menus :

var menu = new UI.Menu({
sections: [{
title: 'First section',
items: [{
title: 'First Item',
subtitle: 'Some subtitle',
icon: 'images/item_icon.png'
}, {
title: 'Second item'
}]
}]
});

关于javascript - Pebble JS、GitHub 和图像资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28971979/

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