2013-03-13 49 views
0

我有下面的代碼塊:開始的Javascript:如何運行多個功能的JavaScript塊

(function() { 
    QUnit.config.testTimeout = 10000; 

    var stringformat = QUnit.stringformat; 

    module('Web API GET Result has expected shape'); 



    asyncTest('HomeData should return an array of Sets with their info as well as cards with their info, but no sides',   
     function() { 
      $.ajax({ 
        url: '/sample/url', 
        dataType: 'json', 
        success: function (result) { 
         ok(
          !!result.item, 'Got something'); 
         start(); 
        }, 
        error: function(result) { 
         ok(false, 'Failed with: ' + result.responseText); 
         start(); 
        } 
       } 

      ); 
     } 
     ); 

    return function() { asyncTest(); }; 

    } 

我試圖用不同的結果,多個URL運行它,但我想不出如何使用不同的參數運行兩次asyncTest。我試着將函數(asyncTest的第二個參數)分配給一個變量並將其插入到asyncTest()中,但這不起作用。我如何定義多個「asyncTest」並運行它們?

回答

0

$ .deferred(),$ .when()和$ .pipe()是你的朋友,如果你使用jQuery [明顯的代碼]。上面的好教程是here,here