當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript knockout.computed函數代碼示例

本文整理匯總了TypeScript中knockout.computed函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript computed函數的具體用法?TypeScript computed怎麽用?TypeScript computed使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了computed函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: constructor

    constructor(language: string, framework: string) {
        this.language = ko.observable(language);
        this.framework = ko.observable(framework);
        this.firstname = ko.observable("");
        this.lastname = ko.observable("");
        this.result = ko.observable(""); 
        this.firstNumber = ko.observable(0);
        this.secondNumber = ko.observable(0);
        this.secondNumberConverted = ko.observable(0);

        this.fullname = ko.computed({
            owner: this,
            read: () => {
                return (this.firstname() == "") ? "" : "Hello, " + this.firstname() + " " + this.lastname() + "!";
            }
        });

        this.firstNumberConverted = ko.computed({
            owner: this,
            read: () => {
                return parseFloat(this.firstNumber().toString());
            }
        });

        this.secondNumber.subscribe((newSecondNumber) => {
            this.secondNumberConverted(parseFloat(newSecondNumber.toString()));            
        });

    }
開發者ID:ocdsoft,項目名稱:TypeScriptKnockoutSample,代碼行數:29,代碼來源:hello.ts

示例2: constructor

    constructor() {
        this.loading = ko.observable<boolean>(false);
        this.cardsVariantRadio = ko.observable("down");
        this.orientationModeRadio = ko.observable<ScreenOrientation>("landscape");
        this.selectOrientationModeAllowed = ko.computed(() =>
            appConfig.ui.usePortraitAndLandscapeOrientationModes,
        );
        this.selectCardsVariantAllowed = ko.computed(() =>
            appConfig.joinTable.allowTickets,
        );

    }
開發者ID:online-poker,項目名稱:poker-html-client,代碼行數:12,代碼來源:settingspopup.ts

示例3: it

  it('should support being a dependency of knockout observables', function() {
    const gObs = observable(17);
    const gComp = computed((use) => use(gObs) * 2);
    const kObs = ko.observable("foo");

    // Check that multiple calls to wrap don't create different observables.
    const kWrap = toKo(ko, gObs);
    assert.strictEqual(toKo(ko, gObs), kWrap);

    const stub = sinon.stub().returnsArg(0);
    const kComp = ko.computed(() => stub([toKo(ko, gObs)(), toKo(ko, gComp)(), kObs(), kWrap()]));

    assert.deepEqual(kComp.peek(), [17, 34, "foo", 17]);
    assertResetSingleCall(stub, undefined, [17, 34, "foo", 17]);

    kObs("bar");
    assert.deepEqual(kComp.peek(), [17, 34, "bar", 17]);
    assertResetSingleCall(stub, undefined, [17, 34, "bar", 17]);

    gObs.set(5);
    assert.deepEqual(kComp.peek(), [5, 10, "bar", 5]);
    assert.deepEqual(stub.args, [[[5, 34, "bar", 5]], [[5, 10, "bar", 5]]]);
    stub.resetHistory();

    // If we dispose the computed, there are no more calls to it.
    kComp.dispose();
    kObs("foo");
    gObs.set(17);
    sinon.assert.notCalled(stub);
  });
開發者ID:gristlabs,項目名稱:grainjs,代碼行數:30,代碼來源:kowrap.ts

示例4: 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

示例5: 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

示例6: it

        it("should return same value if given parameter is a computed", () => {
            var val = ko.observable(commonHelpers.createNoteArray()),
                value = ko.computed(val),
                result = utils.createObservable(value);

            ko.isSubscribable(result).should.be.ok;
            result.should.equal(value);
        });
開發者ID:spatools,項目名稱:koutils,代碼行數:8,代碼來源:utils.ts

示例7: testReadonlyComputed

function testReadonlyComputed() {
    const write = ko.computed({
        read: () => {},
        write: () => {},
    });

    // Can cast a computed as readonly
    const read: ReadonlyComputed<any> = write;
    read();
    // read("foo"); // $ExpectError // no way to test this currently
}
開發者ID:Retsam,項目名稱:knockout,代碼行數:11,代碼來源:test-readonly.ts

示例8: constructor

 constructor() {
     super();
     this.tournaments = ko.observableArray([]);
     this.tournamentsCaption = ko.computed(() => {
         return _("tournamentsList.headerCaption")
             .replace("#count", this.tournaments().length.toString());
     }, this);
     this.loading = ko.observable(false);
     this.slider = new Slider();
     this.slider.addOption(_("lobby.cashGames"), "cash", null);
     this.slider.addOption(_("lobby.tournaments"), "tournaments", null);
     this.slider.addOption(_("lobby.sitAndGo"), "sng", null);
     this.slider.selectPrev();
 }
開發者ID:online-poker,項目名稱:poker-html-client,代碼行數:14,代碼來源:tournamentslistpage.ts

示例9: target

    ko.extenders["options"] = (target: KnockoutObservable<any>, option: { caption: string; items: SelectorItem[]}) => {
        target.options = option.items;
        target.caption = option.caption;
        target.currentValue = ko.computed(() => {
            const value = target();
            const selectedItem = option.items.filter((item: SelectorItem) => {
                return item.value === value;
            });
            if (selectedItem.length === 0) {
                return "";
            }

            return selectedItem[0].text;
        });
        return target;
    };
開發者ID:online-poker,項目名稱:poker-html-client,代碼行數:16,代碼來源:extenders.ts

示例10: constructor

 constructor() {
     this.one = ko.observable();
     this.two = ko.observable();
     this.sum = ko.computed({
         owner: this,
         read: () => {
             if (this.one() != undefined && this.two() != undefined) {
                 return (parseInt(this.one()) + parseInt(this.two()));
             } else {
                 return;    
             }
             
         }
     });
     //this.model = new Backbone.Model({});
 }
開發者ID:kashifjawed,項目名稱:CCTracking,代碼行數:16,代碼來源:KoBindingView.ts


注:本文中的knockout.computed函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。