将变量传递给JavaScript中另一个函数的函数(winJs)

时间:2013-10-21 10:00:28

标签: javascript json winjs

您好我正在使用 Java Script

使用Windows 8应用
function fetchFromLiveProvider(currentList, globalList,value) {
    feedburnerUrl = currentList.url,
    feedUrl = "http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&output=json&num=999&q=" + encodeURIComponent(feedburnerUrl);
        WinJS.xhr({url: feedUrl, responseType: "rss/json"
        }).done(function complete(result) {
                 var jsonData = JSON.parse(result.response);
                    //console.log(JSON.stringify(jsonData));
                 var entries = jsonData.responseData.feed;
               });
    }
function setOther(entries){ 
       //some code here
    }

我想要的是将fetchFromLiveProvider函数中的条目传递给另一个名为 setOther(entries){} 的函数。谢谢你的帮助...

1 个答案:

答案 0 :(得分:0)

由于WinJS.xhr返回一个承诺,您可以执行以下操作:

var entriesPromise = function fetchFromLiveProvider(currentList, globalList, value) {
    feedburnerUrl = currentList.url,
    feedUrl = "http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&output=json&num=999&q=" + encodeURIComponent(feedburnerUrl);
    return WinJS.xhr({
        url: feedUrl,
        responseType: "rss/json"
    });
}

function setOther(entries) {
    entries.done(function complete(result) {
        var jsonData = JSON.parse(result.response);
        //console.log(JSON.stringify(jsonData));
        var entries = jsonData.responseData.feed;

        //some code here
    })
}

setOther(entriesPromise);