2013-07-17 27 views
1

我有這個代碼與一定的函數來顯示輸出,我必須得到來自JSON的{{url}}值到按鈕的onclick()事件。它在此代碼下面陳述。 查看下面代碼中的代碼段,搜索「更多」。它帶有onclick()的按鈕。PhoneGap中的JSON解析

fixlinedetail: function() { 


       window.tBuilder.tpl[tType.linedetail] = function (a) { 
        var b = $("#dvLineReview_Buttons .button.shiny-blue").css({'vertical-align': 'top', width: (setting.basic.screenW - 105) + 'px', 'height':'33px', 'text-shadow':'none', 'top':'0', 'margin-top':'3px','margin-right': '50px'}), 
         c = "", 
         d = { 
          id: a.id, 
          info: _.unescapeHTML(globalData.decode(a.info)), 
          phone: a.phone, 
          email: a.email, 
          url: a.url, 
          IMGS: a.images, 
          logo: "'" + a.logo + "'" 
         }; 
        b[!0 === a.follow || "true" === a.follow || 1 === a.follow || "1" === a.follow ? "show" : "hide"](); 
        jqobject.layout.slideIn.lineDetail.Map.change(a.coord.lat, a.coord.lng, { 
         isPreview: !0 
        }); 

        c = $(_.mTemplate('<article style="min-height: 170px;"><div class="stack twisted" data-imgIndex="0"><div style="background-image: url({{{logo}}});"></div></div> {{{info}}}</article> <a id="btnAddToCal_Review" class="button skip off" href="#">Add to Calendar</a> <a class="button skip" href="tel:{{phone}}">Call Us</a> <a class="button skip" href="mailto:{{email}}">Email Us</a> <button class="button skip" onclick="inappbrowser()" type="submit"> More </button>', 
        d)); 
        !d.logo && 0 === d.IMGS.length ? c.find(".stack").hide() : 0 !== d.IMGS.length && (d.logo || c.filter(".stack div").css("background-image", 'url("' + d.imgs[0] + '")'), c.filter(".stack").fastClick(function() { 
         var a = $(this); 
         global.ImageSlider.triggerSlides(a, d.id, d.imgs, a.data("imgIndex")) 
        })); 
        if (!1 === !a.date && (!0 !== !a.date.start || !0 !== !a.date.start) && !a.date.complete) try { 
          !1 === global.data.method.customer.event.options.check(a.id).added && c.filter("#btnAddToCal_Review").removeClass("off").css({ 
           display: "block" 
          }).attr("onclick", 
          _.mTemplate("if(confirm(" + _.quote("Are you sure you wish to add this event?") + ")) { $(this).hide(); window.Pl.calendar.createEvent({{{ id }}}, {{{ title }}},{{{ location }}},{{{ notes }}},{{{ startDate }}},{{{ endDate }}}); }; return false;", { 
           id: _.quote(a.id), 
           title: _.quote(globalData.decode(a.name)), 
           location: _.quote(globalData.decode(a.address)), 
           notes: '" "', 
           startDate: _.quote(a.date.start), 
           endDate: _.quote(a.date.end) 
          })) 
        } catch (f) {} 
        return c 
       } 
      }, 

主要的問題是這個函數(下面陳述)超出了範圍。

function inappbrowser() { 
        iabRef = window.open('url', '_blank', 'location=yes'); 
        iabRef.addEventListener('loadstart', iabLoadStart); 
        iabRef.addEventListener('loadstop', iabLoadStop); 
        iabRef.removeEventListener('loaderror', iabLoadError); 
        iabRef.addEventListener('exit', iabClose); 
       } 

告訴我一種獲取函數中'url'字段{{url}}值的方法。

回答

1

嗨,哥們有一個爲你解決

更換的更多的錨標記通過下面的代碼

<a class="button skip" href="#" onclick="inappbrowser(&#39;{&quot;key&quot;: &quot;{{url}}&quot;}&#39;); return false" > Read More </a> 

和inappbrowser的功能做到這一點

function inappbrowser(json) { 

       iabRef = window.open(JSON.parse(json).key, '_blank', 'location=no'); 
       iabRef.addEventListener('loadstart', iabLoadStart); 
       //iabRef.addEventListener('loadstop', iabLoadStop); 
       //iabRef.removeEventListener('loaderror', iabLoadError); 
       iabRef.addEventListener('exit', iabClose); 
      } 
+0

是啊,這是很好的!謝謝 ... – MAST3RMIND