【问题标题】:UI/template module not found NativeScript未找到 UI/模板模块 NativeScript
【发布时间】:2017-06-17 12:37:45
【问题描述】:

关于 ui/template 模块,我不断收到以下错误:

file:///app/tns_modules/tns-core-modules/ui/builder/builder.js:195:56: JS ERROR Error: Building UI from XML. @file:///app/main-page.xml:38:13
     > Module 'ui/template' not found for element 'Template'.
       > Could not find module 'ui/template'. Computed path 

由于某种原因,我无法在 NativeScript 中使用 <template> 标记来编写以下代码:

 <GridLayout>

  <ListView items="{{ groceryList }}" itemTemplateProperty="list-group" itemTap="navigateToTasks" separatorColor="white">
        <ListView.itemTemplate>
            <template>
                <Label text="{{ name }}" class="list-group-item-heading"  />
            </template>
            <template>
                <Label text="{{ grocery }}" class="list-group-item-heading"  />
            </template>
        </ListView.itemTemplate>

    </ListView> 
</GridLayout>

我构建数组如下:

var pageData = new observableModule.fromObject({
    groceryList: new ObservableArray([
        { name: "Cool" },
        { name: "bread" },
        { name: "cereal"},
        { grocery: "id"}
            ])
});

由于某种原因,我也无法包含 ui/template 模块,因为它没有找到。我尝试将以下内容放在 main-page.js 中:

var ObservableArray = require("data/observable-array").ObservableArray;

但它显然不起作用。

【问题讨论】:

  • 同样的问题...找到解决方案了吗?

标签: javascript android ios arrays nativescript


【解决方案1】:

我花了一段时间才弄明白,但是一旦你引入了多个模板,你需要将 ListView.itemTemplate 更改为 ListView.itemTemplates(即末尾的 's' !)

 <GridLayout>

  <ListView items="{{ groceryList }}" itemTemplateProperty="list-group" itemTap="navigateToTasks" separatorColor="white">
        <ListView.itemTemplates>
            <template>
                <Label text="{{ name }}" class="list-group-item-heading"  />
            </template>
            <template>
                <Label text="{{ grocery }}" class="list-group-item-heading"  />
            </template>
        </ListView.itemTemplates>

    </ListView> 
</GridLayout>

【讨论】:

    猜你喜欢
    • 2018-03-21
    • 1970-01-01
    • 1970-01-01
    • 2020-11-20
    • 1970-01-01
    • 2017-01-02
    • 1970-01-01
    • 2021-04-13
    • 1970-01-01
    相关资源
    最近更新 更多