2015-10-20 42 views
-1

我想要一個函數來返回我經常使用的條件語句的參數,但是我無法得到如何在字符串內匹配函數參數。下面是函數:JS:如何將函數參數包含到大塊字符串中

function conditionForLinks(textNum, linkNum){ 
    return "${typeof(contentAsset.custom.brandInfoLinkUrl+textNum) !== 'undefined' && contentAsset.custom.brandInfoLinkUrl+textNum && 
typeof(contentAsset.custom.brandInfoLinkText+linkNum) !== 'undefined' && contentAsset.custom.brandInfoLinkText+textNum}" 
} 
+1

的typeof(contentAsset.custom.brandInfoLinkUrl + textNum) - 這是什麼應該是什麼? :P – nowhere

+0

它是demandware腳本,ds是電子商務平臺 –

+0

是contentAsset.custom.brandInfoLinkUrl應該是一個數字嗎? – nowhere

回答

-1

謝謝這個工程:

function conditionForLinks(textNum, linkNum){ 
      return "${typeof(contentAsset.custom.brandInfoLinkUrl"+textNum+") !== 'undefined' && contentAsset.custom.brandInfoLinkUrl"+textNum+" && typeof(contentAsset.custom.brandInfoLinkText"+linkNum+") !== 'undefined' && contentAsset.custom.brandInfoLinkText"+textNum+"}" 
     } 
1

你想擁有通過單變量傳遞多個參數?如

function foo(i, j){ 
 
     
 
    } 
 
    
 
    var bar="1,2"; 
 
    foo(bar);

如果是這樣嘗試

var bar= {i:1, j:2}; 
相關問題