0

I am using a sample application with kendo mobile and require js. I am trying to navigate to a new view from another view. Once i go to the view, i have to alert or print a value. Like to check whenever i am in the view. I am using some sample code from kendo music store. I cant print anything inside that view. Find the below code.

main.js

var app;

require.config({
paths: {
    jQuery: "../kendo/js/jquery.min",
    kendo: "../kendo/js/kendo.mobile.min"       
},
shim: {
    jQuery: {
        exports: "jQuery"
    },
    kendo: {
        exports: "kendo"
    }
}

});

require(["jQuery", "app"], function($, application) {
$(function() {
    app = application
    application.init();
});

});

app.js

define(["jQuery", "kendo", "about-view", "account-view", "utils", "home-view"], function($,
            kendo, aboutView, accountView, utils, homeView) {

        var _onError = function(error, url, line) {

        };

        var init = function() {
            window.onerror = _onError;

            var kendoApp = new kendo.mobile.Application(document.body, {
                        transition : "fade",
                        initial : "login-view",
                        loading : '<h1 class="loading-message">Loading...</h1>'
                    });
            utils.init(kendoApp);
        };

        return {
            aboutView : aboutView,
            accountView : accountView,
            utils : utils,
            homeView : homeView,
            init : init
        };
    });

Below is the new view i am creating to alert a value whenever i navigate to that view

define(["jQuery", "kendo", "utils"], function($, kendo, utils) {

return {
    init: function(){
        console.log("init home view");
    },
};

});

my index.html has that view already, i am able to see the view once i navigate, but i cant do print or alert any value whenever i navigate to that view.

<div data-role="view" id="home-view" data-layout="home-layout" data-title="Home" data-model="app.homeView.viewModel">
        <p>
            Test para1
        </p>
        <p>Test para2
        </p>
    </div>
    <!-- <script src="cordova.js"></script> -->
    <!-- RequireJS is a JavaScript file and module loader(Below main.js file is set to load) -->
    <script data-main="scripts/main.js" src="scripts/require.js"></script>
4

2 回答 2

1

您可以向视图 div 添加额外的属性来绑定生命周期事件,如下所示:

<div data-role="view" data-layout="home-layout" 
   id="home-view" data-title="Home" 
   data-init="app.homeView.init"
   data-model="app.homeView.viewModel">

还有其他可以绑定的事件(例如显示、隐藏) - 完整列表在Mobile View 文档中

于 2013-09-30T13:24:41.947 回答
0

如果您想在进入此视图时显示警报,则可以使用 data-show 之类的

<div data-role="view" id="home-view" data-model="app.homeView.viewModel" data-show="app.homeView.init">
于 2014-01-06T09:00:01.787 回答