Sitecore SPEAK初学者在使用Javascript时遇到问题

ali*_*lms 3 sitecore sitecore7 sitecore-speak-ui

我正在尝试编写我的第一个简单的Sitecore Speak组件.

没什么好看的,我只需要开始.所以我在Visual Studio中创建了我的Speak组件,在Sitecore中,我的渲染指向了我的组件.这一切都是开箱即用的.我在我的SPEAK布局上插入我的渲染,当我访问该页面时,我收到一个错误说明这一点 在此输入图像描述

任何人都知道为什么?我需要做什么?我正在使用Sitecore 7.5.

我的cshtml看起来像这样:

@using Sitecore.Mvc
@using Sitecore.Mvc.Presentation
@using Sitecore.Web.UI.Controls.Common.UserControls
@model RenderingModel
@{
  var rendering = Html.Sitecore().Controls().GetUserControl(Model.Rendering);
  rendering.Class = "sc-Test2";
  rendering.Requires.Script("client", "Test2.js");

  var htmlAttributes = rendering.HtmlAttributes;
}      
<div @htmlAttributes>

</div>
Run Code Online (Sandbox Code Playgroud)

Kom*_*u85 7

基本上这里的问题是Sitecore SPEAK无法找到您的组件的JavaScript.

您似乎在自己的目录中拥有SPEAK组件渲染和javascript,这是最佳做法.您需要做的是告诉SPEAK在哪里寻找您的组件.这是在Include文件夹中的Sitecore SPEAK配置中控制的.

下面是一个补丁包含文件的示例,用于在SPEAK目录中修补以查找javascript组件.

将源设置为包含自定义组件的目录.Deep = true参数将扫描子目录.另请注意此示例中的类别名称"MikeRobbins".选择对您的组件有意义的任何内容,我会避免使用Sitecore来不影响sitecore标准组件.

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <speak.client.resolveScript>
        <processor type="Sitecore.Resources.Pipelines.ResolveScript.Controls, Sitecore.Speak.Client">
        <sources hint="raw:AddSource">
          <source folder="/sitecore/shell/client/MikeRobbins/Layouts/Renderings" deep="true" category="mikerobbins" pattern="*.js,*.css" />
        </sources>
        </processor>
      </speak.client.resolveScript>
    </pipelines>
  </sitecore>
</configuration>
Run Code Online (Sandbox Code Playgroud)

更新你的组件CSHTML并设置userControl.Requires.Script("mikerobbins" .....一部分,你在上面选择的类别名称.请参见下面的例子.

@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("mikerobbins", "JsonDataSource.js");
    userControl.Attributes["type"] = "text/x-sitecore-jsondatasource";
    userControl.DataBind = "Json: json";
    var htmlAttributes = userControl.HtmlAttributes;
}
<script @htmlAttributes>
</script>
Run Code Online (Sandbox Code Playgroud)

这方面的一个例子可以在我的项目中看到.https://github.com/sobek1985/SitecoreSPEAKBulkRolePermissions

希望这会有所帮助,任何问题都会让我大呼过瘾.