Kendo UI +不要执行数据点击

时间:2014-03-27 13:42:51

标签: javascript jquery kendo-mobile

我很擅长要求尝试使用我的剑道移动应用程序获得良好的结构。

我有以下内容:

app.js

define(["jQuery", "kendo", "app/views/home", "app/views/login"], function ($, kendo, homeView, loginView) {
  var _kendoApplication;

  return {
    init: function () {
      _kendoApplication = new kendo.mobile.Application(document.body, {
        transition: "slide"
      });
    },
    views: {
      home: homeView,
      login: loginView
    }
  }
});

Main.js

require.config({
    paths: {
        jQuery: "libs/jquery.min",
        kendo: "libs/kendo.mobile.min"
    },
    shim: {
        jQuery: {
            exports: "jQuery"
        },
        kendo: {
            deps: ["jQuery"],
            exports: "kendo"
        }
    }
});


var app;

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

login.js

define(['kendo'], function () {
    return {
        init: function (initEvt) {
            alert('init login');
        },

        beforeShow: function (beforeShowEvt) {
            // ... before show event code ...
        },

        show: function (showEvt) {
            // ... show event code ...
        },
        viewModel: kendo.observable({
            message: "This rocks!",
            userLogin: function (e) {
                //  alert($('#loginUserName').val());
                alert('dsds');
            }
        })
    }
});

的index.html

<!-- Login View -->
<div data-role="view" id="login-view" data-layout="child" data-title="Login"
data-init="app.views.login.init"
data-before-show="app.views.login.beforeShow"
data-show="app.views.login.show">

  <ul data-role="listview" data-style="inset" data-type="group" id="activities-listview">
    <li>
      Login
      <ul>
        <li>
          <label>
            Username: 
            <span id="fooBar">
              <input type="text" id="loginUserName" value="">
            </span>
          </label>
        </li>
        <li>
          <label>
            Password: 
            <span id="fooBar">
              <input type="text" id="loginUserPassword" value="">
            </span>
          </label>
        </li>
      </ul>
    </li>
  </ul>
  <h1 data-bind="text: message">
  </h1>
  <ul data-role="listview" id="listItemFinish">
    <li data-icon="add">
      <a data-role="button" data-click="app.views.login.userLogin" data-icon="arrow-e">
        Finish
      </a>
    </li>
  </ul>
</div>

现在,我尝试通过userLogin拨打data-bind="events:{click: app.views.login.userLogin}",但收到以下错误:

Uncaught TypeError: Object [object Object] has no method 'apply'

我可以确认数据绑定正常,因为我能够绑定message变量。

我做错了吗?

1 个答案:

答案 0 :(得分:0)

经理解决这个问题。问题确实缺乏理解。对于那些感兴趣的人来说,要调用数据绑定点击事件,我所要做的就是以下内容:

Login.js

define(['kendo', 'app/utils/utils'], function (kendo, utils) {
return {
    init: function (initEvt) {
       alert('init login');
                 alert(utils.getCredits());
    },

    beforeShow: function (beforeShowEvt) {
        // ... before show event code ...
    },

    show: function (showEvt) {
        // ... show event code ...
    },
            viewModel: kendo.observable({
                        message: "This rocks!",
                            userLogin: function (e) {
                                alert($('#loginUserName').val());

                            }
                    })
            }

});

的index.html

<li data-icon="add"><a data-role="button" data-bind="click: userLogin" data-icon="arrow-e">Finish</a>

我试图通过app.Views.Login.userLogin调用。