本文整理汇总了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;未经允许,请勿转载。 |
请发表评论