สร้างองค์ประกอบ H1 พื้นฐาน

คุณสามารถลบเนื้อหาส่วนใหญ่ในไฟล์ที่เป็นตัวเลือก เพื่อสร้างองค์ประกอบ H1 องค์ประกอบจะแสดงข้อความส่วนหัวที่คุณกำหนดเป็นตัวเลือกเมื่อสร้าง viewModel ถัดจากนั้น คุณสามารถระบุการตั้งค่าและสไตล์สำหรับองค์ประกอบนี้ได้

ในการตรวจสอบโครงสร้างขององค์ประกอบในระบบ ให้ทำดังนี้

  1. ค้นหาองค์ประกอบของคุณและซิงโครไนซ์กับระบบไฟล์ โดยใช้แอปพลิเคชันการซิงโครไนซ์บนเดสก์ท็อปของ Oracle Content Management

    • ในแอปการซิงโครไนซ์บนเดสก์ท็อปเวอร์ชันล่าสุด ให้เลือกตัวเลือก เริ่มต้นซิงโครไนซ์ หรือ เลือกโฟลเดอร์ที่จะซิงโครไนซ์

    • ถ้าคุณไม่มีแอปพลิเคชันการซิงโครไนซ์บนเดสก์ท็อป คุณสามารถเลือกองค์ประกอบในแท็บ องค์ประกอบ ของ Oracle Content Management จากนั้นดริลล์ดาวน์เพื่อดูไฟล์ต่างๆ

  2. ถ้าคุณแสดงไฟล์ภายในองค์ประกอบ คุณจะเห็นไฟล์เหล่านี้

    • ไฟล์องค์ประกอบในโฟลเดอร์ ข้อมูล

      • render.js

      • settings.html

    • appinfo.json: ไฟล์ JSON ที่มีคำอธิบายขององค์ประกอบ

      โปรดดู เกี่ยวกับการพัฒนาองค์ประกอบ

    • folder_icon.jpg: ไอคอนที่แสดงในแคตตาล็อกองค์ประกอบ

ในการสร้างองค์ประกอบ H1 ให้ทำดังนี้

  1. เปิดไฟล์ appinfo.json และแทนที่เนื้อหาด้วยรายการต่อไปนี้
    {
       "id": "h1-component-id",
    
       "settingsData": {
                 "settingsHeight": 90,
                 "settingsWidth": 300,
                 "settingsRenderOption": "inline",
                 "componentLayouts": [ ],
                 "triggers": [ ],
                 "actions": [ ]
       },
       "initialData": {
                 "componentId": "h1-component-id",
                 "customSettingsData": {
                         "headingText": "Heading 1"
                 },
                 "nestedComponents": [ ]
       }
    }
  2. เปิดไฟล์ render.js ในโฟลเดอร์ assets ในโปรแกรมแก้ไขข้อความที่คุณชื่นชอบ
  3. แก้ไขเนื้อหาของ render.js เป็นรายการต่อไปนี้
    /* globals define */
    define(['knockout', 'jquery', 'text!./render.html'], function(ko, $, template) {
      'use strict';
      // ----------------------------------------------
      // Define a Knockout ViewModel for your template
      // ----------------------------------------------
      var SampleComponentViewModel = function(args) {
        var SitesSDK = args.SitesSDK;
        // create the observables -- this allows updated settings to automatically update the HTML on the page
        this.headingText = ko.observable();
    
        //
        // Handle property changes from the Settings panel
        //
        this.updateCustomSettingsData = $.proxy(function(customData) {
          this.headingText(customData && customData.headingText);
        }, this);
        this.updateSettings = function(settings) {
          if (settings.property === 'customSettingsData') {
            this.updateCustomSettingsData(settings.value);
          } 
        };
        // Register your updateSettings listener to recieve SETTINGS_UPDATED events
        SitesSDK.subscribe(SitesSDK.MESSAGE_TYPES.SETTINGS_UPDATED, $.proxy(this.updateSettings, this)); 
    
        //
        // Get the initial settings data for the component and apply it
        //
        SitesSDK.getProperty('customSettingsData', this.updateCustomSettingsData);
      };
    
    
      // ----------------------------------------------
      // Create a knockout based component implemention
      // ----------------------------------------------
      var SampleComponentImpl = function(args) {
        // Initialze the custom component
        this.init(args);
      };
      // initialize all the values within the component from the given argument values
      SampleComponentImpl.prototype.init = function(args) {
        this.createViewModel(args);
        this.createTemplate(args);
        this.setupCallbacks();
      };
      // create the viewModel from the initial values
      SampleComponentImpl.prototype.createViewModel = function(args) {
        // create the viewModel
        this.viewModel = new SampleComponentViewModel(args);
      };
      // create the template based on the initial values
      SampleComponentImpl.prototype.createTemplate = function(args) {
        // create a unique ID for the div to add, this will be passed to the callback
        this.contentId = args.id + '_content_' + args.viewMode;
        // create a hidden custom component template that can be added to the DOM
        this.template = '<div id="' + this.contentId + '">' + 
          template + 
          '</div>';      
      };
      //
      // SDK Callbacks
      // setup the callbacks expected by the SDK API
      //
      SampleComponentImpl.prototype.setupCallbacks = function() {
        //
        // callback - render: add the component into the page
        //
        this.render = $.proxy(function(container) {
          var $container = $(container);
          // add the custom component template to the DOM
          $container.append(this.template);
          // apply the bindings
          ko.applyBindings(this.viewModel, $('#' + this.contentId)[0]);
        }, this);
        //
        // callback - dispose: cleanup after component when it is removed from the page
        //
        this.dispose = $.proxy(function() {
          // nothing required for this sample since knockout disposal will automatically clean up the node
        }, this);
      };
      // ----------------------------------------------
      // Create the factory object for your component
      // ----------------------------------------------
      var sampleComponentFactory = {
        createComponent: function(args, callback) {
          // return a new instance of the component
          return callback(new SampleComponentImpl(args));
        }
      };
      return sampleComponentFactory;
    });
  4. ในโฟลเดอร์ assets ให้สร้างไฟล์ใหม่ render.html เพื่อใช้เป็นเทมเพลท HTML แบบง่ายขององค์ประกอบนี้
  5. ใช้เนื้อหาต่อไปนี้ในไฟล์ render.html:
    <h1 data-bind="text: headingText()">  
    </h1> 

    ในขั้นตอนนี้ โฟลเดอร์ assets ขององค์ประกอบจะมีสามไฟล์

    • render.html
    • render.js
    • settings.html

เพิ่มองค์ประกอบ H1 ใหม่ไปยังเพจของคุณ (จุดตรวจสอบ 2)