简体   繁体   English

Kendo UI +要求不执行数据单击

[英]Kendo UI + Require not executing data-click

I am pretty new to require so trying to get a good level of structure going with my kendo mobile app. 我是一个非常新的要求,因此尝试使Kendo移动应用程序具有良好的结构水平。

I have the following: 我有以下几点:

app.js 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 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 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 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>

Now, I am trying to call the userLogin via data-bind="events:{click: app.views.login.userLogin}" but getting the following error: 现在,我正在尝试通过data-bind="events:{click: app.views.login.userLogin}"调用userLogin ,但出现以下错误:

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

I can confirm data-binding is working as I am able to bind the message variable. 我可以确认数据绑定正在工作,因为我能够绑定message变量。

Am I doing something wrong? 难道我做错了什么?

Manager to solve this. 经理解决了这个问题。 Issue was indeed lack of understanding. 问题确实是缺乏理解。 For those of you interested, to call the data-bind click event, all I had to do was the following: 对于您感兴趣的人,只需调用以下操作即可调用数据绑定单击事件:

Login.js 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 Index.html

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

I was attempting to call via app.Views.Login.userLogin. 我试图通过app.Views.Login.userLogin调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM