本文整理汇总了TypeScript中knockout.components类的典型用法代码示例。如果您正苦于以下问题:TypeScript components类的具体用法?TypeScript components怎么用?TypeScript components使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了components类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: registerDropdown
export function registerDropdown(): boolean {
if (!ko.bindingHandlers.msoptions)
addMsDropdownBindingHandler();
if (!ko.components.isRegistered(DROPDOWN_COMPONENT)) {
ko.components.register(DROPDOWN_COMPONENT, {
template: DropdownView.templateHtml,
viewModel: DropdownViewModel
});
}
return true;
}
示例2: return
return (target: { new (...args) }) => {
if (!ko.components.isRegistered(options.selector)) {
if (!options.template && !options.templateUrl) {
throw Error(`Component ${target.name} must have template`);
}
const factory = getFactory(target);
const config = {
template: options.template || { require: options.templateUrl },
viewModel: factory
};
ko.components.register(options.selector, config);
}
};
示例3: registerHomePageViewModel
export function registerHomePageViewModel() {
ko.components.register('home-page',{
viewModel: {
createViewModel: (params,componentInformation) : IHomePageViewModel => {
var viewModel = kernel.get<IHomePageViewModel>("IHomePageViewModel");
viewModel.init(params);
return viewModel;
}
},
template: componentTemplate
});
}
示例4: registerComponent
public registerComponent(name: string, location: string)
{
ko.components.register(name, { require: location });
}
示例5: initApplication
/// <reference path="../typings/browser.d.ts" />
import * as ko from 'knockout';
import { BuildingViewModel, buildingTemplate } from './components/building';
import { CivViewModel, civTemplate } from './components/civilization';
import * as game from './services/game';
ko.components.register('building', { viewModel: BuildingViewModel, template: buildingTemplate });
ko.components.register('civilization', { viewModel: CivViewModel, template: civTemplate });
if (document.readyState === "loading") {
document.onreadystatechange = () => { if (document.readyState === "interactive") initApplication(); }
}
else{
initApplication();
}
function initApplication(){
const myCiv = new game.Civilisation();
ko.applyBindings({ civ: myCiv });
}
示例6: require
// const log = log4js.getLogger("app.main");
const log = {
trace: console.log,
fatal: console.log
};
import * as ko from "knockout";
import { sleep } from "@zxnode/base";
import AppViewModel from "./ViewModels/AppViewModel";
// Register widgets
log.trace("Registering Knockout widget: app-view");
ko.components.register("app-view", {
template: require("./Views/AppView.html")
});
// Initializing and start
log.trace("Creating application view model");
const appVM = new AppViewModel();
log.trace("Initializing application view model");
Promise.all([
appVM.init(),
sleep(1)
]).then(() => {
log.trace("Activates knockout.js");
ko.applyBindings(appVM);
}).catch((reason) => {
log.fatal("Crash", reason);
alert("Crash");
示例7: remove
function remove() {
widgets.remove(this);
}
return {
widgets,
addCalculator,
addToDoList,
addWeather,
addTranslate,
remove
};
}
ko.components.register('calculator', {
viewModel: { require: 'lib/calculator' },
template: { require: 'text!lib/calculator.html' }
});
ko.components.register('todo-list', {
viewModel: { require: 'lib/todo-list' },
template: { require: 'text!lib/todo-list.html' }
});
ko.components.register('weather', {
viewModel: { require: 'lib/weather' },
template: { require: 'text!lib/weather.html' }
});
ko.components.register('translate', {
viewModel: { require: 'lib/translate' },
template: { require: 'text!lib/translate.html' }
示例8:
/// <reference path="./../references.d.ts" />
import * as ko from "knockout";
import * as $ from "jquery";
import * as bootstrap from "bootstrap";
import * as router from "./router";
// Components can be packaged as AMD modules, such as the following:
ko.components.register('nav-bar', { require: 'components/nav-bar/nav-bar' });
ko.components.register('home-page', { require: 'components/home-page/home' });
// ... or for template-only components, you can just point to a .html file directly:
ko.components.register('about-page', {
template: { require: 'text!components/about-page/about.html' }
});
// [Scaffolded component registrations will be inserted here. To retain this feature, don't remove this comment.]
// Start the application
ko.applyBindings({ route: router.currentRoute });
示例9: createBrowserHistory
import './css/site.css';
import 'bootstrap';
import * as ko from 'knockout';
import { createBrowserHistory } from 'history';
import './webpack-component-loader';
import AppRootComponent from './components/app-root/app-root';
const baseUrl = document.getElementsByTagName('base')[0].getAttribute('href')!;
const basename = baseUrl.substring(0, baseUrl.length - 1); // History component needs no trailing slash
// Load and register the <app-root> component
ko.components.register('app-root', AppRootComponent);
// Tell Knockout to start up an instance of your application
ko.applyBindings({ history: createBrowserHistory({ basename }), basename });
// Basic hot reloading support. Automatically reloads and restarts the Knockout app each time
// you modify source files. This will not preserve any application state other than the URL.
if (module.hot) {
module.hot.accept();
module.hot.dispose(() => ko.cleanNode(document.body));
}
示例10:
// Validation
ko.validation.init({
grouping : { deep: true, observable: true },
decorateInputElement: true,
parseInputAttributes: true,
decorateElementOnModified: false,
messagesOnModified: false,
errorElementClass: 'has-error',
errorMessageClass: 'help-block'},
true);
/* Pages */
ko.components.register('home-page', {
template: {
require: 'components/home-page/home.html!text'
},
viewModel: {
require: 'components/home-page/home'
}
});
ko.components.register('about-page', {
template: {
require: 'components/about-page/about.html!text'
},
viewModel: {
require: 'components/about-page/about'
}
});
ko.components.register('contact-page', {
template: {