首页 > 解决方案 > 在 Bixby 中,有没有办法以特定顺序在图像选择器中显示图像或按图像名称对其进行排序?

问题描述

我正在尝试向用户显示几张图像,让他们选择任何一张图像,并且我希望图像按特定顺序排列或根据其名称进行排序。但每次选择屏幕加载图像似乎都是随机的。

这就是我传递图像的方式:

  default-init {
    intent {
      goal: Image
      value: Image {
        url: viv.core.Url("/images/img1.png")
      }
      value: Image {
        url: viv.core.Url("/images/img2.png")
      }
      value: Image {
        url: viv.core.Url("/images/img3.png")
      }
      value: Image {
        url: viv.core.Url("/images/img4.png")
      }
      value: Image {
        url: viv.core.Url("/images/img5.png")
      }
      value: Image {
        url: viv.core.Url("/images/img6.png")
      }
    }
  }

这是输入视图:

  input-view {
    match: Image (this) {
      to-input: SelectImage 
    }

    message {
       template (Choose any image?)
    }

    render {
      image-picker (this) {
        size (Medium)
    }
  }
}    

我希望它们以给定的顺序显示或根据它们的名称进行排序(在这种情况下是相同的)。我该怎么办?

标签: bixbybixbystudio

解决方案


如果您在动作模型中列出值,则它没有任何顺序并且是随机的。

一个简单的解决方案是创建一个没有输入的单独操作,并在默认初始化中使用该操作。然后在链接的 JS 函数中,返回一个图像对象数组。显示顺序将是数组索引顺序。

更改默认初始化部分

    default-init {
    intent {
      goal: GetDefaultImage
    }

添加操作 GetDefaultImage

action(GetDefaultImage) {
  type(Search) 
  output(Image)
}

链接的 JS 文件(将其链接到您的端点文件中)

module.exports.function = function getDefaultImage () {
  var result = []
  // result should be in the format of result[0].url = 'imageUrl1'
  //                                   result[1].url = 'imageUrl2'
  return result;
}

推荐阅读