资源加载器有什么问题?

时间:2016-01-08 14:13:38

标签: javascript jquery headjs

我的页面包含代码

    <script type="text/javascript" src="${pageContext.request.contextPath}/javascript/head.load.min.js"></script>
    <script type="text/javascript"> 
        head.load([ '${pageContext.request.contextPath}/javascript/timecookie.js',
                    'http://code.jquery.com/jquery-1.10.2.min.js' ],
                function() {
                    console.log("Done loading resources");
                });
    </script>

<script type="text/javascript">
<!-- this fuction does not work -->
$(document).ready(function(){ 
    $(function(){
        $('button').click(function(){
            console.log("running");
            var url='myapp.com/mainpage.jsp?check='+this.id;
            alert(url);
        });
    });
});

</script>

我认为jquery(它已被加载)不能正常运行这样的加载。 resouces loader有什么问题?

1 个答案:

答案 0 :(得分:0)

请您尝试使用以下方法:

<?php namespace Your\Controllers\Namespace;

use Your\Namespace\Helper;

class YourController extends Controller{

    protected $helper;

    public function __construct(Helper $helper){
        $this->helper = $helper;
    }

    public function pageName1(){
        return $this->helper->header1()->loadView('mockup/pagename1');
    }

    public function pageName2(){  
        return $this->helper->header2()->loadView('mockup/pagename2');
    }

    public function customPage3(){
        //setting on the controller

        $panelTexts = [
            "Some Random line One for page 3",
            "Some Random Line Two for page 3",
        ];

        return $this->helper->setPanelText($panelTexts)->loadView('mockup/pagename3');
    }
}