从umbraco中的多值数据类型中检索数据

时间:2019-02-23 13:13:17

标签: angularjs razor umbraco umbraco7

我使用Umbraco 7.13.1

我已经创建了一个自定义数据类型,并且运行良好。但是现在我需要将数据渲染到页面的模板中。

app_pluggin

js文件

angular.module('umbraco').controller('IBD_HeaderController', function ($scope) {

    $scope.model.value.Tag = $scope.model.value.Tag || "default value";
    $scope.model.value.HeadingText = $scope.model.value.HeadingText || "default value";

    console.log($scope.model);

    $scope.SetTag = function () {
        $scope.model.value.Tag = $scope.value.Tag
    };
});

html文件

<div class="IBD_CMS" ng-controller="IBD_HeaderController">
    <div>
        <input class="headingTextBox" type="text" ng-model="model.value.HeadingText" ng-change="SetHeading()">
    </div>
    <div class="HeadingTag">
        <label class="TagOption">
            <input type="radio" name="HeadingTag" value="h1" ng-model="model.value.Tag" ng-click="SetTag()">
            <span>H1</span>
        </label>
        <label class="TagOption">
            <input type="radio" name="HeadingTag" value="h2" ng-model="model.value.Tag" ng-click="SetTag()">
            <span>H2</span>
        </label>
        <label class="TagOption">
            <input type="radio" name="HeadingTag" value="h3" ng-model="model.value.Tag" ng-click="SetTag()">
            <span>H3</span>
        </label>
        <label class="TagOption">
            <input type="radio" name="HeadingTag" value="h4" ng-model="model.value.Tag" ng-click="SetTag()">
            <span>H4</span>
        </label>
        <label class="TagOption">
            <input type="radio" name="HeadingTag" value="h5" ng-model="model.value.Tag" ng-click="SetTag()">
            <span>H5</span>
        </label>
        <label class="TagOption">
            <input type="radio" name="HeadingTag" value="h6" ng-model="model.value.Tag" ng-click="SetTag()">
            <span>H6</span>
        </label>
    </div>
</div>

清单

{
  propertyEditors:[
    {
      alias: "IBD.Heading",
      name: "Intelligence By Design Heading",
      editor: {
        view: "~/App_Plugins/IBD.Heading/IBD.Heading.View.html",
        valueType: "JSON"
      }
    }
  ],
  javascript: [
    "~/App_Plugins/IBD.Heading/IBD.Heading.js"
  ],
  css: [
    "~/App_Plugins/IBD.Heading/style.css"
  ]
}

我可以在内容编辑器中设置信息,并将其全部存储。

我的问题是如何将它作为2个单独的值重新存入cshtml文件中

ie Model.content.ComponentName.HeadingText Model.content.ComponentName.Tag

我目前有

pageHeading = Model.Content.GetPropertyValue<string>("cartName");

这将返回

{“ TAG”:“ H3”,“ HEADINGTEXT”:“ MY CART”}

我想要这个

pageHeading =我的购物车 pageHeadingTag = h3

2 个答案:

答案 0 :(得分:0)

您应该创建自己的C#类来表示您的对象,例如

public class TagClass {
    public string TAG{get;set;}
    public string HEADINGTEXT{get;set;}
}

然后您可以实现自己的属性值转换器 https://our.umbraco.com/documentation/extending/property-editors/value-converters https://skrift.io/articles/archive/custom-property-value-converters/

或者也许只是反序列化它:

var tagClass = JsonConvert.DeserializeObject<YourClass>(Model.Content.GetPropertyValue<string>("cartName"));

答案 1 :(得分:0)

感谢eyecream在昨晚解决了它,创建了一个模型和控制器,然后调用了该函数,该函数将字符串反序列化为模型,然后返回给cshtml文件。您的看上去很简单,但是我想在跟踪过程中向插件添加更多变量,所以我认为我的长期工作也可以完成