本文整理匯總了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()));
});
}
示例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,
);
}
示例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);
});
示例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();
});
}
示例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');
}
示例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);
});
示例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
}
示例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();
}
示例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;
};
示例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({});
}