首页 > 解决方案 > 未找到元素“nativescript-drop-down:DropDown”的模块“nativescript-drop-down”

问题描述

我收到以下错误。

来自设备 Savas 的日志:“主”线程上发生未捕获的异常。调用 js 方法 onClick 失败错误:从 XML 构建 UI。@purchase/page.xml:3:5

未找到元素“nativescript-drop-down:DropDown”的模块“nativescript-drop-down”。无法读取未定义的属性“setNative”

StackTrace:SourceError(file:///data/数据/org.nativescript.preview/files/app/tns_modules/@nativescript/core/utils/debug.js:74:23)


我的源代码:Xml 文件


<!--
`<Page xmlns="http://schemas.nativescript.org/tns.xsd" loaded="pageLoaded" xmlns:dd="nativescript-drop-down">
  <GridLayout rows="auto, auto, *" columns="auto, *">
    <dd:DropDown items="{{ items }}" selectedIndex="{{ selectedIndex }}" 
                 opened="dropDownOpened" closed="dropDownClosed" 
                 selectedIndexChanged="dropDownSelectedIndexChanged"
                 row="0" colSpan="2" />
    <Label text="Selected Index:" row="1" col="0" fontSize="18" verticalAlignment="bottom"/>
    <TextField text="{{ ad }}" row="1" col="1" />
  </GridLayout>
</Page>`
-->

JS文件


const fromObject = require("tns-core-modules/data/observable").fromObject;

exports.pageLoaded = function (args) {

  const items = [];
  items.push({
    ad: "Batman"
  });
  items.push({
    ad: "Joker"
  });
  items.push({
    ad:"Bane"
  });

  const page = args.object;
  const vm = fromObject({
    items: items
  });
  page.bindingContext = vm;

}

标签: drop-down-menunativescript

解决方案


很抱歉问这个显而易见的问题,但是您确实安装了插件,是吗?

tns plugin add nativescript-drop-down

推荐阅读