• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript knockout.utils类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中knockout.utils的典型用法代码示例。如果您正苦于以下问题:TypeScript utils类的具体用法?TypeScript utils怎么用?TypeScript utils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了utils类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: update

  /**
   * This will be called once when the binding is first applied to an element,
   * and again whenever any observables/computeds that are accessed change
   */
  public update(element: any, valueAccessor: () => any, allBindingsAccessor?: KnockoutAllBindingsAccessor,
    viewModel?: any, bindingContext?: KnockoutBindingContext): void {
    this.removePreviousContent(element);

    let unwrappedArray: any = ko.utils.unwrapObservable(valueAccessor());
    let captionValue: any;
    let filteredArray: {}[] = [];
    let itemSelected: (evt: MouseEvent) => any;

    if (unwrappedArray) {
      if (typeof unwrappedArray.length == "undefined") // Coerce single value into array
        unwrappedArray = [unwrappedArray];

      // Filter out any entries marked as destroyed
      filteredArray = ko.utils.arrayFilter(unwrappedArray, (item) => {
        return item === undefined || item === null || !ko.utils.unwrapObservable(item['_destroy']);
      });

      // If caption is included, add it to the array
      if (allBindingsAccessor['has']('optionsCaption')) {
        captionValue = ko.utils.unwrapObservable(allBindingsAccessor.get('optionsCaption'));
        // If caption value is null or undefined, don't show a caption
        if (captionValue !== null && captionValue !== undefined) {
          filteredArray.unshift({ value: "-1", text: captionValue });
        }
      }
    } else {
      // If a falsy value is provided (e.g. null), we'll simply empty the select element
    }

    if (allBindingsAccessor['has']('itemSelected'))
      itemSelected = allBindingsAccessor.get('itemSelected') as (evt: MouseEvent) => any;
    this.addNewContent(element, filteredArray, allBindingsAccessor.get('value'), itemSelected);
  }
开发者ID:,项目名称:,代码行数:38,代码来源:


示例2: function

function history<T>(initialValue?: T): history.HistoryObservable<T> {
    const self = {
        latestValues: ko.observableArray([initialValue]),
        selectedIndex: ko.observable(0),
        canGoBack: ko.pureComputed(() => self.selectedIndex() > 0),
        canGoNext: ko.pureComputed(() => self.selectedIndex() < self.latestValues().length - 1)
    } as any;

    ko.utils.extend(self, history.fn);

    const result: any = ko.pureComputed({
        read: () => {
            const values = self.latestValues();
            let index = self.selectedIndex();

            if (index > values.length) {
                index = 0;
            }

            return values[index];
        },
        write: (value: any) => {
            const
                index = self.selectedIndex(),
                values = self.latestValues();

            if (value !== values[index]) {
                if (index !== values.length - 1) {
                    values.splice(index + 1);
                }

                values.push(value);
                self.selectedIndex(index + 1);
            }
        }
    }).extend({ notify: "reference" });

    ko.utils.extend(result, self);

    const oldDispose = result.dispose;
    result.dispose = function () {
        oldDispose.call(this);
        this.canGoBack.dispose();
        this.canGoNext.dispose();
    };

    return result;
}
开发者ID:spatools,项目名称:koutils,代码行数:48,代码来源:history.ts


示例3: config

	config(config) {
		ko.utils.arrayForEach(config.routes,(route: any) => {
			crossroads.addRoute(route.url,(requestParams) => {
				this.currentRoute(ko.utils.extend(requestParams, route.params));
			});
		});
		//crossroads.routed.add(console.log, console);
		this.activateCrossroads();
	}
开发者ID:robertsundstrom,项目名称:express-knockout-spa,代码行数:9,代码来源:router.ts


示例4: addNewContent

  /**
   * This method adds all the options and also updates selected item and text
   */
  private addNewContent(element: any, options: {}[], selectedValue: KnockoutObservable<string>, itemSelected: (evt: MouseEvent) => any): void {
    const titleEl: HTMLSpanElement = element.querySelector('span');
    const listEl = element.querySelector('ul');
    let selectedValueUnwrapped: string = selectedValue && ko.utils.unwrapObservable(selectedValue);
    let selectedValueChanged: boolean = false;

    if (!listEl || !titleEl)
      throw new Error('Incorrect markup in ms-Dropdown element');

    for (let i: number = 0, len: number = options.length; i < len; i++) {
      const liEl: HTMLLIElement = document.createElement('li');
      const option = options[i];
      liEl.textContent = option['text'];
      liEl.setAttribute('aria-value', option['value']);
      liEl.setAttribute('role', 'option');
      liEl.setAttribute('aria-text', option['text']);
      liEl.className = 'ms-Dropdown-item';

      let isSelected: boolean = false;

      if (selectedValueUnwrapped && selectedValueUnwrapped === option['value'])
        isSelected = true;
      else {
        isSelected = option['selected'] === true || option['selected'] === true || option['selected'] === 'selected';
        if (isSelected) {
          selectedValueUnwrapped = option['value'];
          selectedValueChanged = true;
        }
      }

      liEl.setAttribute('aria-selected', isSelected + '');

      if (isSelected) {
        titleEl.textContent = option['text'];
        liEl.className += ' is-selected';
      }

      if (itemSelected) {
        liEl.addEventListener('click', itemSelected);
      }

      listEl.appendChild(liEl);
    }

    if (!titleEl.textContent && options.length > 0) {
      titleEl.textContent = options[0]['text'];
      listEl.children[0].setAttribute('aria-selected', 'true');
      selectedValueUnwrapped = options[0]['value'];
      selectedValueChanged = true;
    }

    if (selectedValueChanged && selectedValue)
      selectedValue(selectedValueUnwrapped);
  }
开发者ID:,项目名称:,代码行数:57,代码来源:


示例5: function

    init: function (element, valueAccessor) {
        const $element = $(element);
        let value = valueAccessor(),
            options = ko.unwrap(value),
            id = $element.attr("id"),
            oldSetup, editor;

        if (typeof options === "object") {
            value = options.value;
            delete options.value;
        }
        else {
            options = {};
        }

        if (!id) {
            id = tinymce.DOM.uniqueId();
            $element.attr("id", id);
        }

        ko.utils.extend(options, defaults);

        oldSetup = options.setup;
        options.setup = (editor) => {
            oldSetup && oldSetup.call(undefined, editor);
        };

        if ($element.is("textarea"))
            $element.val(ko.unwrap(value));
        else {
            $element.html(ko.unwrap(value));
            options.inline = true;
        }

        editor = new tinymce.Editor(id, options, tinymce.EditorManager);
        editor.on("change keyup nodechange", () => {
            if (ko.isWriteableObservable(value)) value(editor.getContent());
        });

        // To prevent a memory leak, ensure that the underlying element"s disposal destroys it"s associated editor.
        ko.utils.domNodeDisposal.addDisposeCallback(element, () => {
            if (editor) {
                editor.remove();
                editor = null;
            }
        });

        editor.render();
    },
开发者ID:spatools,项目名称:koui,代码行数:49,代码来源:tinymce.ts


示例6: onOpenDropdown

  /**
   * Open-close dropdown handler
   */
  public onOpenDropdown(vm: DropdownViewModel, evt: MouseEvent) {
    if (this.disabled())
      return;
    const isOpen: boolean = ko.utils.unwrapObservable(this.isOpen);
    evt.stopPropagation();
    this.isOpen(!isOpen);

    if (!isOpen) {
      if (DropdownViewModel._openedDropdownVM && DropdownViewModel._openedDropdownVM !== this) {
        DropdownViewModel._openedDropdownVM._onDocClick(null);
      }

      DropdownViewModel._openedDropdownVM = this;
      document.addEventListener('click', this._onDocClick);
    }
  }
开发者ID:,项目名称:,代码行数:19,代码来源:


示例7: trigger

export function trigger(element: HTMLElement, eventType: string, eventArgs: any): void {
    let evt;
    if (doc.createEvent) {
        evt = doc.createEvent("HTMLEvents");
        evt.initEvent(eventType, true, true);
    } else {
        evt = doc.createEventObject();
        evt.eventType = eventType;
    }

    evt.eventName = eventType;
    ko.utils.extend(evt, eventArgs);

    if (doc.createEvent) {
        element.dispatchEvent(evt);
    } else {
        element.fireEvent("on" + evt.eventType, evt);
    }
}
开发者ID:spatools,项目名称:koui,代码行数:19,代码来源:event.ts


示例8: actionClick

  /**
   * Expand\collapse click handler
   */
  protected actionClick(ev: MouseEvent): void {
    this.isExpanded(!this.isExpanded());

    const isExpanded = this.isExpanded();

    if (isExpanded) {
      const unwrappedTerms = ko.utils.unwrapObservable(this.terms);

      if (!unwrappedTerms || !unwrappedTerms.length) {
        this.model.getChildTerms(this.entity).then((terms) => {
          const termViewModels: TermViewModel[] = [];
          terms.forEach((value) => {
            termViewModels.push(new TermViewModel(this.model, value));
          });

          this.terms(termViewModels);
        });
      }
    }
  }
开发者ID:,项目名称:,代码行数:23,代码来源:


示例9:

 key: data => ko.utils.unwrapObservable(data.id),
开发者ID:typed-contrib,项目名称:knockout.mapping,代码行数:1,代码来源:test.ts


示例10:

 filteredArray = ko.utils.arrayFilter(unwrappedArray, (item) => {
   return item === undefined || item === null || !ko.utils.unwrapObservable(item['_destroy']);
 });
开发者ID:,项目名称:,代码行数:3,代码来源:



注:本文中的knockout.utils类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript knockout.validation类代码示例发布时间:2022-05-25
下一篇:
TypeScript knockout.tasks类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap