v5.20191.603
|

wijmo 模块

Contains utilities used by all controls and modules, as well as the Control and Event classes.

变量

culture

culture: any

Gets or sets an object that contains all localizable strings in the Wijmo library.

The culture selector is a two-letter string that represents an ISO 639 culture.

方法

addClass

  • addClass(e: Element, className: string): void
  • Adds a class to an element.

    参数

    • e: Element

      Element that will have the class added.

    • className: string

      Class (or space-separated list of classes) to add to the element.

    返回值 void

animate

  • animate(apply: Function, duration?: number, step?: number): any
  • Calls a function on a timer with a parameter varying between zero and one.

    Use this function to create animations by modifying document properties or styles on a timer.

    For example, the code below changes the opacity of an element from zero to one in one second:

    var element = document.getElementById('someElement');
    animate(function(pct) {
      element.style.opacity = pct;
    }, 1000);

    The function returns an interval ID that you can use to stop the animation. This is typically done when you are starting a new animation and wish to suspend other on-going animations on the same element. For example, the code below keeps track of the interval ID and clears if before starting a new animation:

    var element = document.getElementById('someElement');
    if (this._animInterval) {
      clearInterval(this._animInterval);
    }
    var self = this;
    self._animInterval = animate(function(pct) {
      element.style.opacity = pct;
      if (pct == 1) {
        self._animInterval = null;
      }
    }, 1000);

    参数

    • apply: Function

      Callback function that modifies the document. The function takes a single parameter that represents a percentage.

    • 可选 duration: number

      The duration of the animation, in milliseconds.

    • 可选 step: number

      The interval between animation frames, in milliseconds.

    返回值 any

    An interval id that you can use to suspend the animation.

asArray

  • asArray(value: any, nullOK?: boolean): any[]
  • Asserts that a value is an array.

    参数

    • value: any

      Value supposed to be an array.

    • 可选 nullOK: boolean

      Whether null values are acceptable.

    返回值 any[]

    The array passed in.

asBoolean

  • asBoolean(value: boolean, nullOK?: boolean): boolean
  • Asserts that a value is a Boolean.

    参数

    • value: boolean

      Value supposed to be Boolean.

    • 可选 nullOK: boolean

      Whether null values are acceptable.

    返回值 boolean

    The Boolean passed in.

asCollectionView

asDate

  • asDate(value: Date, nullOK?: boolean): Date
  • Asserts that a value is a Date.

    参数

    • value: Date

      Value supposed to be a Date.

    • 可选 nullOK: boolean

      Whether null values are acceptable.

    返回值 Date

    The Date passed in.

asEnum

  • asEnum(value: number, enumType: any, nullOK?: boolean): number
  • Asserts that a value is a valid setting for an enumeration.

    参数

    • value: number

      Value supposed to be a member of the enumeration.

    • enumType: any

      Enumeration to test for.

    • 可选 nullOK: boolean

      Whether null values are acceptable.

    返回值 number

    The value passed in.

asFunction

  • asFunction(value: any, nullOK?: boolean): Function
  • Asserts that a value is a function.

    参数

    • value: any

      Value supposed to be a function.

    • 可选 nullOK: boolean

      Whether null values are acceptable.

    返回值 Function

    The function passed in.

asInt

  • asInt(value: number, nullOK?: boolean, positive?: boolean): number
  • Asserts that a value is an integer.

    参数

    • value: number

      Value supposed to be an integer.

    • 可选 nullOK: boolean

      Whether null values are acceptable.

    • 可选 positive: boolean

      Whether to accept only positive integers.

    返回值 number

    The number passed in.

asNumber

  • asNumber(value: number, nullOK?: boolean, positive?: boolean): number
  • Asserts that a value is a number.

    参数

    • value: number

      Value supposed to be numeric.

    • 可选 nullOK: boolean

      Whether null values are acceptable.

    • 可选 positive: boolean

      Whether to accept only positive numeric values.

    返回值 number

    The number passed in.

asString

  • asString(value: string, nullOK?: boolean): string
  • Asserts that a value is a string.

    参数

    • value: string

      Value supposed to be a string.

    • 可选 nullOK: boolean

      Whether null values are acceptable.

    返回值 string

    The string passed in.

asType

  • asType(value: any, type: any, nullOK?: boolean): any
  • Asserts that a value is an instance of a given type.

    参数

    • value: any

      Value to be checked.

    • type: any

      Type of value expected.

    • 可选 nullOK: boolean

      Whether null values are acceptable.

    返回值 any

    The value passed in.

assert

  • assert(condition: boolean, msg: string): void
  • Throws an exception if a condition is false.

    参数

    • condition: boolean

      Condition expected to be true.

    • msg: string

      Message of the exception if the condition is not true.

    返回值 void

changeType

  • changeType(value: any, type: DataType, format?: string): any
  • Changes the type of a value.

    If the conversion fails, the original value is returned. To check if a conversion succeeded, you should check the type of the returned value.

    参数

    • value: any

      Value to convert.

    • type: DataType

      DataType to convert the value to.

    • 可选 format: string

      Format to use when converting to or from strings.

    返回值 any

    The converted value, or the original value if a conversion was not possible.

clamp

  • clamp(value: number, min: number, max: number): number
  • Clamps a value between a minimum and a maximum.

    参数

    • value: number

      Original value.

    • min: number

      Minimum allowed value.

    • max: number

      Maximum allowed value.

    返回值 number

closest

  • closest(e: any, selector: string): Element
  • Finds the closest ancestor (including the original element) that satisfies a selector.

    参数

    • e: any

      Element where the search should start.

    • selector: string

      A string containing a selector expression to match elements against.

    返回值 Element

    The closest ancestor that satisfies the selector, or null if not found.

closestClass

  • closestClass(e: any, className: string): Node
  • Finds the closest ancestor (including the original element) that satisfies a class selector.

    参数

    • e: any

      Element where the search should start.

    • className: string

      A string containing the class name to match elements against.

    返回值 Node

    The closest ancestor that has the specified class name, or null if not found.

contains

  • contains(parent: any, child: any, popup?: boolean): boolean
  • Checks whether an HTML element contains another.

    参数

    • parent: any

      Parent element.

    • child: any

      Child element.

    • 可选 popup: boolean

      Whether to take Wijmo popups into account.

    返回值 boolean

    True if the parent element contains the child element.

copy

  • copy(dst: any, src: any): void
  • Copies properties from an object to another.

    This method is typically used to initialize controls and other Wijmo objects by setting their properties and assigning event handlers.

    The destination object must define all the properties defined in the source, or an error will be thrown.

    参数

    • dst: any

      The destination object.

    • src: any

      The source object.

    返回值 void

createElement

  • createElement(html: string, appendTo?: HTMLElement): HTMLElement
  • Creates an element from an HTML string.

    参数

    • html: string

      HTML fragment to convert into an HTMLElement.

    • 可选 appendTo: HTMLElement

      Optional HTMLElement to append the new element to.

    返回值 HTMLElement

    The new element.

disableAutoComplete

  • disableAutoComplete(e: HTMLInputElement): void
  • Disables the autocomplete, autocorrect, autocapitalize, and spellcheck properties of an input element.

    参数

    • e: HTMLInputElement

      The input element.

    返回值 void

enable

  • enable(e: HTMLElement, value: boolean): void
  • Enables or disables an element.

    参数

    • e: HTMLElement

      Element to enable or disable.

    • value: boolean

      Whether to enable or disable the element.

    返回值 void

escapeHtml

  • escapeHtml(text: string): string
  • Escapes a string by replacing HTML characters with text entities.

    Strings entered by users should always be escaped before they are displayed in HTML pages. This helps ensure page integrity and prevent HTML/javascript injection attacks.

    参数

    • text: string

      Text to escape.

    返回值 string

    An HTML-escaped version of the original string.

format

  • format(format: string, data: any, formatFunction?: Function): string
  • Replaces each format item in a specified string with the text equivalent of an object's value.

    The function works by replacing parts of the formatString with the pattern '{name:format}' with properties of the data parameter. For example:

    var data = { name: 'Joe', amount: 123456 };
    var msg = wijmo.format('Hello {name}, you won {amount:n2}!', data);
    

    The format function supports pluralization. If the format string is a JSON-encoded object with 'count' and 'when' properties, the method uses the 'count' parameter of the data object to select the appropriate format from the 'when' property. For example:

    var fmt = {
        count: 'count',
        when: {
            0: 'No items selected.',
            1: 'One item is selected.',
            2: 'A pair is selected.',
            'other': '{count:n0} items are selected.'
        }
    }
    fmt = JSON.stringify(fmt);
    console.log(wijmo.format(fmt, { count: 0 })); // No items selected.
    console.log(wijmo.format(fmt, { count: 1 })); // One item is selected.
    console.log(wijmo.format(fmt, { count: 2 })); // A pair is selected.
    console.log(wijmo.format(fmt, { count: 12 })); 12 items are selected.
    

    The optional formatFunction allows you to customize the content by providing context-sensitive formatting. If provided, the format function gets called for each format element and gets passed the data object, the parameter name, the format, and the value; it should return an output string. For example:

    var data = { name: 'Joe', amount: 123456 };
    var msg = wijmo.format('Hello {name}, you won {amount:n2}!', data,
        function (data, name, fmt, val) {
            if (wijmo.isString(data[name])) {
                val = wijmo.escapeHtml(data[name]);
            }
            return val;
        }
    );
    

    参数

    • format: string

      A composite format string.

    • data: any

      The data object used to build the string.

    • 可选 formatFunction: Function

      An optional function used to format items in context.

    返回值 string

    The formatted string.

getActiveElement

  • getActiveElement(): HTMLElement
  • Gets a reference to the element that contains the focus, accounting for shadow document fragments.

    返回值 HTMLElement

getAggregate

  • getAggregate(aggType: Aggregate, items: any[], binding?: string): any
  • Calculates an aggregate value from the values in an array.

    参数

    • aggType: Aggregate

      Type of aggregate to calculate.

    • items: any[]

      Array with the items to aggregate.

    • 可选 binding: string

      Name of the property to aggregate on (in case the items are not simple values).

    返回值 any

getElement

  • getElement(selector: any): HTMLElement
  • Gets an element from a query selector.

    参数

    • selector: any

      An element, a query selector string, or a jQuery object.

    返回值 HTMLElement

getElementRect

  • getElementRect(e: Element): Rect
  • Gets the bounding rectangle of an element in page coordinates.

    This is similar to the getBoundingClientRect function, except that uses viewport coordinates, which change when the document scrolls.

    参数

    • e: Element

    返回值 Rect

getType

  • Gets the type of a value.

    参数

    • value: any

      Value to test.

    返回值 DataType

    A DataType value representing the type of the value passed in.

getTypes

  • getTypes(arr: any[]): any[]
  • Gets an array containing the names and types of items in an array.

    参数

    • arr: any[]

      Array containing data items.

    返回值 any[]

    An array containing objects with the binding and type of each primitive property in the items found in the input array.

getUniqueId

  • getUniqueId(baseId: string): string
  • Creates a new unique id for an element by adding sequential numbers to a given base id.

    参数

    • baseId: string

      String to use as a basis for generating the unique id.

    返回值 string

getVersion

  • getVersion(): string
  • Gets the version of the Wijmo library that is currently loaded.

    返回值 string

hasClass

  • hasClass(e: Element, className: string): boolean
  • Checks whether an element has a class.

    参数

    • e: Element

      Element to check.

    • className: string

      Class to check for.

    返回值 boolean

hasItems

hidePopup

  • hidePopup(popup: HTMLElement, remove?: any, fadeOut?: boolean): any
  • Hides a popup element previously displayed with the showPopup method.

    参数

    • popup: HTMLElement

      Popup element to hide.

    • 可选 remove: any

      Whether to remove the popup from the DOM or just to hide it. This parameter may be a boolean or a callback function that gets invoked after the popup has been removed from the DOM.

    • 可选 fadeOut: boolean

      Whether to use a fade-out animation to make the popup disappear gradually.

    返回值 any

    An interval id that you can use to suspend the fade-out animation.

httpRequest

  • httpRequest(url: string, settings?: any): XMLHttpRequest
  • Performs HTTP requests.

    The settings parameter may contain the following:

    method The HTTP method to use for the request (e.g. "POST", "GET", "PUT"). The default is "GET".
    data Data to be sent to the server. It is appended to the url for GET requests, and converted to a JSON string for other requests.
    async By default, all requests are sent asynchronously (i.e. this is set to true by default). If you need synchronous requests, set this option to false.
    success A function to be called if the request succeeds. The function gets passed a single parameter of type XMLHttpRequest.
    error A function to be called if the request fails. The function gets passed a single parameter of type XMLHttpRequest.
    complete A function to be called when the request finishes (after success and error callbacks are executed). The function gets passed a single parameter of type XMLHttpRequest.
    beforeSend A function to be called immediately before the request us sent. The function gets passed a single parameter of type XMLHttpRequest.
    requestHeaders A JavaScript object containing key/value pairs to be added to the request headers.
    user A username to be used with XMLHttpRequest in response to an HTTP access authentication request.
    password A password to be used with XMLHttpRequest in response to an HTTP access authentication request.

    Use the success to obtain the result of the request which is provided in the callback's XMLHttpRequest parameter. For example, the code below uses the httpRequest method to retrieve a list of customers from an OData service:

    import { httpRequest } from '@grapecity/wijmo';
    httpRequest('http://services.odata.org/Northwind/Northwind.svc/Customers?$format=json', {
      success: function (xhr) {
        var response = JSON.parse(xhr.responseText),
            customers = response.value;
        // do something with the customers...
      }
    });

    参数

    • url: string

      String containing the URL to which the request is sent.

    • 可选 settings: any

      An optional object used to configure the request.

    返回值 XMLHttpRequest

    The XMLHttpRequest object used to perform the request.

isArray

  • isArray(value: any): boolean
  • Determines whether an object is an Array.

    参数

    • value: any

      Value to test.

    返回值 boolean

isBoolean

  • isBoolean(value: any): boolean
  • Determines whether an object is a Boolean.

    参数

    • value: any

      Value to test.

    返回值 boolean

isDate

  • isDate(value: any): boolean
  • Determines whether an object is a Date.

    参数

    • value: any

      Value to test.

    返回值 boolean

isEmpty

  • isEmpty(obj: any): boolean
  • Determines whether an object is empty (contains no enumerable properties).

    参数

    • obj: any

      Object to test.

    返回值 boolean

isFunction

  • isFunction(value: any): boolean
  • Determines whether an object is a function.

    参数

    • value: any

      Value to test.

    返回值 boolean

isInt

  • isInt(value: any): boolean
  • Determines whether an object is an integer.

    参数

    • value: any

      Value to test.

    返回值 boolean

isNullOrWhiteSpace

  • isNullOrWhiteSpace(value: string): boolean
  • Determines whether a string is null, empty, or whitespace only.

    参数

    • value: string

      Value to test.

    返回值 boolean

isNumber

  • isNumber(value: any): boolean
  • Determines whether an object is a number.

    参数

    • value: any

      Value to test.

    返回值 boolean

isObject

  • isObject(value: any): boolean
  • Determines whether a value is an object (as opposed to a value type, an array, or a Date).

    参数

    • value: any

      Value to test.

    返回值 boolean

isPrimitive

  • isPrimitive(value: any): boolean
  • Determines whether an object is a primitive type (string, number, Boolean, or Date).

    参数

    • value: any

      Value to test.

    返回值 boolean

isString

  • isString(value: any): boolean
  • Determines whether an object is a string.

    参数

    • value: any

      Value to test.

    返回值 boolean

isUndefined

  • isUndefined(value: any): boolean
  • Determines whether an object is undefined.

    参数

    • value: any

      Value to test.

    返回值 boolean

mouseToPage

  • mouseToPage(e: any): Point
  • Converts mouse or touch event arguments into a Point in page coordinates.

    参数

    • e: any

    返回值 Point

moveFocus

  • moveFocus(parent: HTMLElement, offset: number): boolean
  • Moves the focus to the next/previous/first focusable child within a given parent element.

    参数

    • parent: HTMLElement

      Parent element.

    • offset: number

      Offset to use when moving the focus (use zero to focus on the first focusable child).

    返回值 boolean

    True if the focus was set, false if a focusable element was not found.

removeChild

  • removeChild(e: Node): Node
  • Safely removes an element from the DOM tree.

    参数

    • e: Node

      Element to remove from the DOM tree.

    返回值 Node

removeClass

  • removeClass(e: Element, className: string): void
  • Removes a class from an element.

    参数

    • e: Element

      Element that will have the class removed.

    • className: string

      Class (or space-separated list of classes) to remove from the element.

    返回值 void

setAriaLabel

  • setAriaLabel(e: Element, value?: string): void
  • Sets or clears an element's aria-label attribute.

    参数

    • e: Element

      Element that will be updated.

    • 可选 value: string

      Value of the aria label, or null to remove the label from the element.

    返回值 void

setAttribute

  • setAttribute(e: Element, name: string, value?: any, keep?: boolean): void
  • Sets or clears an attribute on an element.

    参数

    • e: Element

      Element that will be updated.

    • name: string

      Name of the attribute to add or remove.

    • 可选 value: any

      Value of the attribute, or null to remove the attribute from the element.

    • 可选 keep: boolean

      Whether to keep original attribute if present.

    返回值 void

setCss

  • setCss(e: any, css: any): void
  • Modifies the style of an element by applying the properties specified in an object.

    参数

    • e: any

      Element or array of elements whose style will be modified.

    • css: any

      Object containing the style properties to apply to the element.

    返回值 void

setLicenseKey

  • setLicenseKey(licenseKey: string): void
  • Sets the license key that identifies licensed Wijmo applications.

    If you do not set the license key, Wijmo will run in evaluation mode, adding a watermark element to the page.

    Licensed users may obtain keys at the My Account section of the Wijmo site.

    Note that Wijmo does not send keys or any licensing information to any servers. It only checks the internal consistency of the key provided.

    参数

    • licenseKey: string

      String containing the license key to use in this application.

    返回值 void

setSelectionRange

  • setSelectionRange(e: any, start: number, end?: number): boolean
  • Sets the start and end positions of a selection in a text field.

    This method is similar to the native setSelectionRange method in HTMLInputElement objects, except it checks for conditions that may cause exceptions (element not in the DOM, disabled, or hidden).

    参数

    • e: any

      HTMLInputElement or HTMLTextAreaElement to select.

    • start: number

      Offset into the text field for the start of the selection.

    • 可选 end: number

      Offset into the text field for the end of the selection.

    返回值 boolean

setText

  • setText(e: HTMLElement, text: string): void
  • Sets the text content of an element.

    参数

    • e: HTMLElement

      Element that will have its content updated.

    • text: string

      Plain text to be assigned to the element.

    返回值 void

showPopup

  • showPopup(popup: HTMLElement, ref?: any, above?: boolean, fadeIn?: boolean, copyStyles?: any): any
  • Shows an element as a popup.

    The popup element becomes a child of the body element, and is positioned above or below a reference rectangle, depending on how much room is available.

    The reference rectangle may be specified as one of the following:

    HTMLElement
    The bounding rectangle of the element.
    MouseEvent
    The bounding rectangle of the event's target element.
    Rect
    The given rectangle.
    null
    No reference rectangle; the popup is centered on the window.

    Call the hidePopup method to hide the popup.

    参数

    • popup: HTMLElement

      Element to show as a popup.

    • 可选 ref: any

      Reference element or rectangle used to position the popup.

    • 可选 above: boolean

      Position popup above the reference rectangle if possible.

    • 可选 fadeIn: boolean

      Use a fade-in animation to make the popup appear gradually.

    • 可选 copyStyles: any

      Whether to copy font and color styles from the reference element, or an element to use as the style source.

    返回值 any

    An interval id that you can use to suspend the fade-in animation.

toFixed

  • toFixed(value: number, prec: number, truncate: boolean): number
  • Rounds or truncates a number to a specified precision.

    参数

    • value: number

      Value to round or truncate.

    • prec: number

      Number of decimal digits for the result.

    • truncate: boolean

      Whether to truncate or round the original value.

    返回值 number

toHeaderCase

  • toHeaderCase(text: string): string
  • Converts a camel-cased string into a header-type string by capitalizing the first letter and adding spaces before uppercase characters preceded by lower-case characters.

    For example, 'somePropertyName' becomes 'Some Property Name'.

    参数

    • text: string

      String to convert to header case.

    返回值 string

toPlainText

  • toPlainText(html: string): string
  • Converts an HTML string into plain text.

    参数

    • html: string

      HTML string to convert to plain text.

    返回值 string

    A plain-text version of the string.

toggleClass

  • toggleClass(e: Element, className: string, addOrRemove?: boolean): void
  • Adds or removes a class to or from an element.

    参数

    • e: Element

      Element that will have the class added.

    • className: string

      Class to add or remove.

    • 可选 addOrRemove: boolean

      Whether to add or remove the class. If not provided, toggle the class.

    返回值 void

tryCast

  • tryCast(value: any, type: any): any
  • Casts a value to a type if possible.

    参数

    • value: any

      Value to cast.

    • type: any

      Type or interface name to cast to.

    返回值 any

    The value passed in if the cast was successful, null otherwise.