【问题标题】:Adapter response isn't displayed in a Dojo ListItem适配器响应未显示在 Dojo ListItem 中
【发布时间】:2014-05-19 16:57:07
【问题描述】:

我正在使用 Worklight 适配器从网站获取 RSS 提要;适配器以 XML 格式获取数据,但问题是我无法在 Dojo LisItem 中显示数据。

这些是调用Adapter的JS函数:

function loadFeedsSuccess(result) {
    console.log("Data sucesfully downloaded, HTTP " + result.status);
    if(result.invocationResult.Items.length > 0) {
        console.log("Server has returned " + result.invocationResult.Items.length + " item(s)"); displayRSSFeed(result.invocationResult.Items);
    } 
}

function loadFeedsFailure(result) {
    console.log("Error while loading RSS feed: " + result.errorMessage);
}

function displayRSSFeed(rawData) {
    var store = new dojo.store.Memory({data:rawData, idProperty: "guid"});
    require(["dijit/registry"], function(registry){ var newsList = registry.byId("newsList"); dojo.empty("newsList");
    store.query(function(news){
        var newsItem = dojox.mobile.ListItem({label:news.title}); newsList.addChild(newsItem); }); 
    });
}

function getNewsInit() {    
    var invocationData = {
        adapter: "FeedReader",
        procedure: "getStoriesFiltered"
    };
    var options = { 
        onSuccess: loadFeedsSuccess,
        onFailure: loadFeedsFailure
    };

    WL.Client.invokeProcedure(invocationData, options); 
}

浏览器不显示数据并显示以下错误:

[/NewsApp/apps/services/api/News/common/query] exception. ReferenceError: dojo is not defined worklight.js:4673
Uncaught ReferenceError: dojo is not defined  

有人知道如何解决我的问题吗?

【问题讨论】:

  • 您是否尝试将所有 dojo 初始化移动到 wlCommonInit
  • 也尝试在你的html中添加这个脚本并测试<script src="//ajax.googleapis.com/ajax/libs/dojo/1.8/dojo/dojo.js"></script>

标签: dojo ibm-mobilefirst worklight-adapters


【解决方案1】:

如果您使用 Dojo 并将 async 配置属性设置为 true,则 dojo 命名空间不再可用。这意味着您不能再使用dojo.store.Memorydojox.mobile.ListItem

要解决该问题,您必须禁用 async 功能或使用 AMD 加载模块:

function displayRSSFeed(rawData) {
    require([ "dijit/registry", "dojo/store/Memory", "dojox/mobile/ListItem", "dojo/dom-construct" ], function(registry, Memory, ListItem, domConstruct) {
        var store = new Memory({data:rawData, idProperty: "guid"});
        var newsList = registry.byId("newsList");
        domConstruct.empty("newsList");
        store.query(function(news){
            var newsItem = new ListItem({label:news.title});
            newsList.addChild(newsItem);
        });
    });
}

如果它抛出错误:

ReferenceError: require is not defined

那么这意味着您正在加载 Dojo 核心,请确保您正在加载 dojo.js

【讨论】:

    猜你喜欢
    • 2012-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多