Sitecore 8 SPEAK:在JS文件中调用方法时出错 [英] Sitecore 8 SPEAK: Getting an Error When calling a Method in JS File

查看:87
本文介绍了Sitecore 8 SPEAK:在JS文件中调用方法时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

单击按钮后,我从Sitecore SPEAK应用程序调用JS文件中的方法时,收到以下错误消息:

When I calling a method in JS file from Sitecore SPEAK application once a button clicked, I'm getting the following error message:

TypeError:this.product不是函数 this.product()

TypeError: this.product is not a function this.product()

this.product()是函数名称:

define(["sitecore"], function (Sitecore) {
var model = Sitecore.Definitions.Models.ControlModel.extend({
    initialize: function (options) {
        this._super();
    },
    products: function () {
        var input = this.get("input");
        $.ajax({
            url: "/api/sitecore/Product/Find",
            type: "POST",
            data: { input: input },
            context: this,
            success: function (data) {
                this.set("output", data);
            }
        });
    },

    product: function () {
        var input2 = this.get("input2");
        $.ajax({
            url: "/api/sitecore/Product/FindSingle",
            type: "POST",
            data: { input2: input2 },
            context: this,
            success: function (data) {
                this.set("output2", data); 
                this.set("output3", data.TitleS);
            }
        });

        return null;
    },
});

var view = Sitecore.Definitions.Views.ControlView.extend({
    initialize: function (options) {
        this._super();
    },
    product: function () {
        this.product();
    }

});

Sitecore.Factories.createComponent("ProductSearch", model, view, ".sc-ProductSearch");

});

从SPEAK Button.Click事件中调用上述方法为: javascript:app.product();

Calling the above method from SPEAK Button.Click event as: javascript:app.product();

如何避免这种情况发生?

What can we do to avoid such case?

推荐答案

尝试一下,

   define(["sitecore"], function (Sitecore) {
        var model = Sitecore.Definitions.Models.ControlModel.extend({
            initialize: function (options) {
                this._super();
                app = this;
            },
        products: function () {}
        });
    }

然后在按钮中单击键入:javascript:app.ProductSearch.product()

And in the button click type: javascript:app.ProductSearch.product()

这篇关于Sitecore 8 SPEAK:在JS文件中调用方法时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆