2014-05-19 51 views
0

我正在使用Worklight適配器從網站獲取RSS源;適配器以XML格式獲取數據,但問題是無法在Dojo LisItem中顯示數據。適配器響應不顯示在Dojo ListItem中

這些都是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); 
} 

瀏覽器不diplay數據的顯示以下錯誤:

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

任何一個有任何想法如何解決我的問題?

+0

你嘗試將所有dojo初始化移動到'wlCommonInit'嗎? – Bluewings

+0

也嘗試添加此腳本在您的HTML和測試'' – Bluewings

回答

2

如果您使用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

+0

Thank You it Works !! ! –