当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript knockout.observable函数代码示例

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


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

示例1: describe

		describe('running validate() with correct values set', () =>
		{
			const validationGroup = new ValidationGroup(values =>
			{
				const fullName = values['first-name'] + ' ' + values['last-name'];
				return (fullName === 'John Doe');
			});

			const firstNameField = new Field('0', null);
			firstNameField.name = 'first-name';
			firstNameField.value = ko.observable();
			firstNameField.groups = validationGroup;

			const lastNameField = new Field('1', null);
			lastNameField.name = 'last-name';
			lastNameField.value = ko.observable();
			lastNameField.groups = validationGroup;

			//noinspection TypeScriptUnresolvedFunction
			firstNameField.value('John');
			//noinspection TypeScriptUnresolvedFunction
			lastNameField.value('Doe');
			it('should resolve with true', () =>
			{
				const validation = validationGroup.validate();
				return expect(validation).to.eventually.equal(true);
			});
		});
开发者ID:flut1,项目名称:knockout-validator,代码行数:28,代码来源:ValidationGroupSpec.ts

示例2: constructor

    constructor(language: string, framework: string) {
        this.language = ko.observable(language);
        this.framework = ko.observable(framework);

        this.ebalo = ko.computed(() => { return 'idi nahui ' + this.language; }, self);
        console.warn('Ebososina roompenji');
    }
开发者ID:duskjet,项目名称:dyysh,代码行数:7,代码来源:main.ts

示例3: constructor

  /**
   * ctor
   * */
  public constructor(_properties: IPropertyPaneViewSelectorFieldPropsInternal) {
    this._properties = _properties;
    this._context = _properties.wpContext;
    this._listId = _properties.listId;
    this._viewId = _properties.viewId;
    this.listLabel = _properties.listLabel;
    this.viewLabel = _properties.viewLabel;
    this.currentList = ko.observable<string>(this._listId);
    this.currentView = ko.observable<string>(this._viewId);
    this.noListSelection = ko.observable<boolean>(this._listId == '-1');

    // subscribing on changes in lists dropdown
    this.currentList.subscribe((value) => {
      const oldListId: string = this._listId;
      this._listId = value;
      this._initViews().then(() => {
        this.noListSelection(this._listId == '-1');
      });

      this._firePropertyChange();

    });

    // subscribing on changes in view dropdown
    this.currentView.subscribe((value) => {
      const oldViewId: string = this._viewId;
      this._viewId = value;
      this._firePropertyChange();
    });

    this.lists = ko.observableArray<IDropdownOption>();
    this.views = ko.observableArray<IDropdownOption>();

    this._model = new PropertyPaneViewSelectorModel(this._context);
  }
开发者ID:,项目名称:,代码行数:38,代码来源:

示例4: constructor

 constructor(){
     this.name = ko.observable<string>("");
     this.age = ko.observable<number>(null);
     this.contacts = ko.observableArray<Person>([]);
     this.itemToAdd = null;
     this.display = ko.observable<string>("");
 }
开发者ID:xiangnanyue,项目名称:mygit2,代码行数:7,代码来源:main.ts

示例5: constructor

 constructor(firstname: string, lastname: string){
     this.firstName = ko.observable(firstname);
     this.lastName =  ko.observable(lastname);
     this.fullName = ko.computed<string>(() => {
         return this.firstName() + " " + this.lastName();
     });
 }
开发者ID:xiangnanyue,项目名称:mygit2,代码行数:7,代码来源:computedOb.ts

示例6: fromJS

export default function fromJS(
  obj: any,
  mapArraysDeep: boolean = false,
  _parentIsArray: boolean = false
): KnockoutObservable<any> | KnockoutObservableTree {
  let obs: KnockoutObservable<any> | KnockoutObservableTree

  if (ko.isObservable(obj)) {
    obs = obj
  } else if (obj instanceof Array) {
    const _arr = []
    for (let i = 0; i < obj.length; i++) {
      _arr[i] = fromJS(obj[i], mapArraysDeep, true)
    }
    obs = ko.observableArray(_arr)
  } else if (obj instanceof Date || obj instanceof RegExp) {
    obs = ko.observable(obj)
  } else if (obj instanceof Function) {
    obs = obj
  } else if (obj instanceof Object) {
    obs = {}
    for (const p in obj) {
      obs[p] = fromJS(obj[p], mapArraysDeep)
    }
  } else {
    obs = _parentIsArray && !mapArraysDeep ? obj : ko.observable(obj)
  }

  return obs
}
开发者ID:Profiscience,项目名称:ko-contrib-utils,代码行数:30,代码来源:fromJS.ts

示例7: createNote

export function createNote(): Note {
    return {
        title: ko.observable("Note #1"),
        date: ko.observable(Date.now()),
        content: ko.observable("This is the content of Note #1")
    };
}
开发者ID:spatools,项目名称:koutils,代码行数:7,代码来源:common.ts

示例8: it

  it('should not create unnecessary subscriptions with computeds', function() {
    const kObsA = ko.observable("a");
    const kObsB = ko.observable("b");
    const spyA = sinon.spy((a: any) => a);
    const spyB = sinon.spy((a: any) => a);
    const gObsA = computed((use) => spyA(use(kObsA)));
    const gObsB = pureComputed((use) => spyB(use(kObsB)));

    // A computed notices a change immediately.
    assertResetSingleCall(spyA, undefined, "a");
    assert.equal(gObsA.get(), "a");
    kObsA("A");
    assertResetSingleCall(spyA, undefined, "A");
    assert.equal(gObsA.get(), "A");
    sinon.assert.notCalled(spyA);

    // pureComputed notices a change only when looked at.
    sinon.assert.notCalled(spyB);
    assert.equal(gObsB.get(), "b");
    assertResetSingleCall(spyB, undefined, "b");
    kObsB("B");
    sinon.assert.notCalled(spyB);
    assert.equal(gObsB.get(), "B");
    assertResetSingleCall(spyB, undefined, "B");

    // This is the crux of the matter: kObsB does not have a subscription.
    assert.equal(kObsA.getSubscriptionsCount(), 1);
    assert.equal(kObsB.getSubscriptionsCount(), 0);     // pureComputed doesn't subscribe when inactive

    // Now subscribe to both gObs computeds.
    const spyA2 = sinon.spy((a: any) => a);
    const spyB2 = sinon.spy((a: any) => a);
    const lisA = gObsA.addListener(spyA2);
    const lisB = gObsB.addListener(spyB2);
    assertResetSingleCall(spyB, undefined, "B");

    // Now pureComputed acts as computed and subscribes too.
    assert.equal(kObsA.getSubscriptionsCount(), 1);
    assert.equal(kObsB.getSubscriptionsCount(), 1);

    kObsA("aa");
    assertResetSingleCall(spyA, undefined, "aa");
    assertResetSingleCall(spyA2, undefined, "aa", "A");
    kObsB("bb");
    assertResetSingleCall(spyB, undefined, "bb");
    assertResetSingleCall(spyB2, undefined, "bb", "B");

    // When we unsubscribe, count should go back to 0.
    lisA.dispose();
    lisB.dispose();
    assert.equal(kObsA.getSubscriptionsCount(), 1);
    assert.equal(kObsB.getSubscriptionsCount(), 0);

    kObsA("AA");
    assertResetSingleCall(spyA, undefined, "AA");
    sinon.assert.notCalled(spyA2);
    kObsB("bb");
    sinon.assert.notCalled(spyB);
    sinon.assert.notCalled(spyB2);
  });
开发者ID:gristlabs,项目名称:grainjs,代码行数:60,代码来源:kowrap.ts

示例9: constructor

 constructor(){
     this.shouldShowMessage=ko.observable(true);
     this.detail=ko.observable("");
     this.peoples=ko.observableArray([]);
     this.displayMessage=ko.observable(false)
     this.products=ko.observableArray([]);
     this.detailsEnable=ko.observable(false);
 }
开发者ID:xiangnanyue,项目名称:mygit2,代码行数:8,代码来源:bindings1.ts


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