【发布时间】:2015-10-09 11:43:07
【问题描述】:
我的问题有点类似于以下未回答的问题。 (虽然不确定) Sitecore 8 SPEAK: Getting an Error When calling a Method in JS File
我正在使用 Sitecore8
在我的页面上有一个按钮,在它的点击事件上我想调用自定义数据源组件的 add()。
布局:
页面的JS代码:
define(["sitecore"], function (Sitecore) {
var JsonListPage = Sitecore.Definitions.App.extend({
initialized: function () {
alert('Inside Json PageList Init');
},
loadData: function () {
alert('Button clicked');
app.add();
}
});
return JsonListPage;
});
自定义数据源组件的JS代码:
define(["sitecore"], function (Sitecore) {
var model = Sitecore.Definitions.Models.ControlModel.extend({
initialize: function (options) {
this._super();
this.set("json", null);
alert('Inside Jsondatasource Init');
},
add: function (data) {
var json = this.get("json");
if (json === null)
json = new Array();
// this is done because array.push changes the array to an object which then do no work on the SPEAK listcontrol.
var newArray = new Array(json.length + 1);
for (var i = json.length - 1; i >= 0; i--)
newArray[i + 1] = json[i];
newArray[0] = data;
this.set("json", newArray);
}
});
var view = Sitecore.Definitions.Views.ControlView.extend({
initialize: function (options) {
this._super();
this.model.set("json", null);
}
});
Sitecore.Factories.createComponent("JsonDatasource", model, view, ".x-sitecore-jsondatasource");
});
.cshtml 用于自定义组件:
@using Sitecore.Mvc
@using Sitecore.Mvc.Presentation
@using Sitecore.Web.UI.Controls.Common.UserControls
@model RenderingModel
@{
var userControl = Html.Sitecore().Controls().GetUserControl(Model.Rendering);
userControl.Requires.Script("client", "JsonDatasource.js");
userControl.Class = "x-sitecore-jsondatasource";
userControl.Attributes["type"] = "text/x-sitecore-jsondatasource";
userControl.DataBind = "Json: json";
var htmlAttributes = userControl.HtmlAttributes;
}
<div @htmlAttributes>
am here again
</div>
页面加载时:
- 它显示来自自定义组件 Init 的警报
- 然后显示来自主机页面初始化的警报
- 单击按钮时会显示警报,然后在“应用程序”上显示错误。
我遗漏了一些内容。任何帮助将不胜感激。如果您需要更多输入,请告诉我。
提前致谢!
【问题讨论】:
标签: sitecore sitecore8 sitecore-speak-ui