For AI agents: the complete documentation index is available at /next/zh/llms.txt, the full documentation bundle is available at /next/zh/llms-full.txt, and this page is available as Markdown at /next/zh/api/lynx-native-api/lynx-view/load-template.md.
Lynx
  • 简体中文
  • loadTemplate

    使用 LynxLoadMeta 渲染 LynxView,是客户端加载 Lynx 模板的主入口。

    语法

    Android

    public void loadTemplate(@NonNull LynxLoadMeta meta);

    参数说明

    • meta: Lynx 模板加载元数据,开发者通过该数据结构指定模板加载的可选数据。

    iOS

    - (void)loadTemplate:(nonnull LynxLoadMeta *)meta;

    参数说明

    • meta: Lynx 模板加载元数据,开发者通过该数据结构指定模板加载的可选数据。

    Harmony

    LynxView 包含以下成员:

    • url: String : 模板文件路径。
    • buffer: ArrayBuffer: 模板的二进制文件数据。
    • templateBundle: TemplateBundle: 由模板的二进制文件数据预先解析的 TemplateBundle 对象。
    • metaData: MetaData: 在首屏加载过程中由客户端指定的初始数据。
    • loadOption: LynxLoadOption: 加载模板时的附加配置信息。
    @Entry
    @Component
    struct Index {
      private url: string = 'playground/main.lynx.bundle';
      private buffer: ArrayBuffer = getTemplateBuffer();
      private metaData = new MetaData(
        new TemplateData('{"text":"TD"}'),
        new TemplateData({ "theme": "Light" }));
    
      build() {
        Column() {
          LynxView({
            url: this.url,
            buffer: this.buffer,
            metadata: this.metaData,
          }).width('100%').height('100%');
        }
        .size({ width: '100%', height: '100%' })
      }
    }

    Web

    const lynxView = document.createElement('lynx-view');
    lynxView.url = 'path/to/your/template.bundle';

    Desktop (C++)

    void LoadTemplate(std::shared_ptr<lynx::pub::LynxLoadMeta> load_meta);

    参数说明

    • load_meta: 用于提供模板 URL、二进制数据、模板包、初始数据和全局属性的加载元数据。

    兼容性

    LCD tables only load in the browser

    除非另有说明,本项目采用知识共享署名 4.0 国际许可协议进行许可,代码示例采用 Apache License 2.0 许可协议进行许可。