如何在函数中传递变量。使用Javascript

时间:2016-08-15 14:12:35

标签: javascript function variables html-framework-7

这是我的代码,一切正常,但我无法在函数$$('.create-popup').on('click', function () {...内传递变量“obj” 我需要将数据放入变量{{contenido}},但我无法访问。

Create-popup函数有效,弹出窗口生成,但我无法获取数据变量将它们传递给函数。

myApp.showPreloader('Cargando notas');
$$.getJSON("http://fabianleguizamon.com.ar/wp-json/wp/v2/posts", function(jsondata){
    myApp.hidePreloader();
    var old=jsondata; 
    //next - your code  
    //var old=data;
    var obj=[];
    for(var i=0;i<old.length;i++){
        var tit=old[i]["title"];
        var con=old[i]["content"];
        var exc=old[i]["excerpt"];
        var fec=new Date(old[i]["date_gmt"]);
        var fec2 = fec.getDate() + '/' +  (fec.getMonth() + 1) + '/' + fec.getFullYear();
        var img=old[i]["better_featured_image"]["media_details"]["sizes"]["oblique-entry-thumb"];
        var bdy=old[i]["acf"];
        var o=[];
        var t={};
        var z={};
        t.id=i+1;
        t.titulo=tit["rendered"];
        t.contenido=con["rendered"];
        t.bajada=exc["rendered"];
        t.enlace=img["source_url"];
        t.fecha=fec2;
        obj.push(t);    
    }

    var myList = myApp.virtualList('.list-block.media-list.virtual-list.accordion-list', {
        items: obj,
        // Custom search function for searchbar
        searchAll: function (query, items) {
            var found = [];
            for (var i = 0; i < items.length; i++) {
                if (items[i].title.indexOf(query) >= 0 || query.trim() === '') found.push(i);
            }
            return found; //return array with mathced indexes
        },
        template: 
        '<li class="accordion-item">' +
        '<a href="#" data-popup="popup{{id}}" class="item-link item-content create-popup">' +
        '<div class="item-inner">' +
        '<div class="item-title-row">' +
        '<div class="item-title">{{titulo}}</div>' +
        '</div>' +
        '<div class="item-text">{{fecha}}</div>' +
        '</div>' +
        '</a>',
        height: 100,
    }); 

    $$('.create-popup').on('click', function () {
        var popupHTML = '<div class="popup">'+
            '<div class="content-block">'+
            '<p>{{contenido}}</p>'+  <---- I can't access here!!!!!
            '<p><a href="#" class="close-popup">Cerrar</a></p>'+
            '</div>'+
            '</div>'
        myApp.popup(popupHTML);
    });
  });

0 个答案:

没有答案