當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。