本文整理汇总了TypeScript中knockout.unwrap函数的典型用法代码示例。如果您正苦于以下问题:TypeScript unwrap函数的具体用法?TypeScript unwrap怎么用?TypeScript unwrap使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了unwrap函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: unwrap
var _selected = selectOptions.filter(item => {
if (allBindings.optionsValue) {
var optionsValue = unwrap(allBindings.optionsValue);
if (typeof (optionsValue) === "string") {
return unwrap(item[optionsValue]) === value;
}
else if (typeof (optionsValue) === "function") {
return unwrap(optionsValue.call(null, item)) === value;
}
}
return item === value;
})[0];
示例2: function
init: function (element, valueAccessor) {
const $element = $(element);
let value = valueAccessor(),
options = ko.unwrap(value),
id = $element.attr("id"),
oldSetup, editor;
if (typeof options === "object") {
value = options.value;
delete options.value;
}
else {
options = {};
}
if (!id) {
id = tinymce.DOM.uniqueId();
$element.attr("id", id);
}
ko.utils.extend(options, defaults);
oldSetup = options.setup;
options.setup = (editor) => {
oldSetup && oldSetup.call(undefined, editor);
};
if ($element.is("textarea"))
$element.val(ko.unwrap(value));
else {
$element.html(ko.unwrap(value));
options.inline = true;
}
editor = new tinymce.Editor(id, options, tinymce.EditorManager);
editor.on("change keyup nodechange", () => {
if (ko.isWriteableObservable(value)) value(editor.getContent());
});
// To prevent a memory leak, ensure that the underlying element"s disposal destroys it"s associated editor.
ko.utils.domNodeDisposal.addDisposeCallback(element, () => {
if (editor) {
editor.remove();
editor = null;
}
});
editor.render();
},
示例3: update
update(element: HTMLElement, valueAccessor: () => KnockoutObservable<string>) {
var text = ko.unwrap(valueAccessor());
text = fixLinks(text, false);
var nickname = authentication.account().userName();
text = text.replace('@' + nickname, '<strong>@' + nickname + '</strong>');
element.innerHTML = text;
}
示例4: merge
export default function merge(
dest: PlainObject,
src: PlainObject,
mapArraysDeep: boolean = false
): KnockoutObservableTree {
const props = Object.keys(src)
for (const prop of props) {
if (isUndefined(dest[prop])) {
dest[prop] = fromJS(src[prop], src[prop] instanceof Array && mapArraysDeep)
} else if (ko.isObservable(dest[prop])) {
dest[prop](
src[prop] instanceof Array && mapArraysDeep
? ko.unwrap(fromJS(src[prop], true))
: src[prop]
)
} else if (isUndefined(src[prop])) {
dest[prop] = undefined
} else if (src[prop].constructor === Object) {
merge(dest[prop], src[prop], mapArraysDeep)
} else {
dest[prop] = src[prop]
}
}
return dest
}
示例5:
static push_and_remove<T> (array : ko.MaybeObservableArray<T>, data: T, plot_size : number)
{
array = ko.unwrap(array);
array.push(data);
if (array.length > plot_size)
array.shift();
}
示例6: _default
// Return default value if the input value is empty or null
static _default (value, defaultValue) {
value = ko.unwrap(value);
if (typeof value === "function") {
return value;
}
if (typeof value === "string") {
return _utils.trim(value) === '' ? defaultValue : value;
}
return value == null || value.length == 0 ? defaultValue : value;
};
示例7: function
init: function (element, valueAccessor, allBindings, viewModel) {
var value = valueAccessor();
var message = ko.unwrap(value.message);
var click = value.click;
ko.applyBindingsToNode(element, {
click: function () {
if (confirm(message))
return click.apply(this, Array.prototype.slice.apply(arguments));
}
}, viewModel);
}
示例8: function
bindingHandler.update = function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
beforeUpdate && beforeUpdate.apply(this, arguments);
const
data = ko.unwrap(valueAccessor()),
templateComputed = ko.renderTemplate(
data.template || bindingHandler.template,
bindingContext.createChildContext(data, name),
{},
element
);
disposeOldComputedAndStoreNewOne(element, templateComputed);
};
示例9:
const cpArray = ko.pureComputed(() => {
if (cpArray[OLD_VALUES_PROPERTY]) {
cpArray[OLD_VALUES_PROPERTY].forEach(d => {
if (typeof d.dispose === "function") {
d.dispose();
}
});
}
const val = ko.unwrap(value);
if (!Array.isArray(val)) {
cpArray[OLD_VALUES_PROPERTY] = null;
return [];
}
return cpArray[OLD_VALUES_PROPERTY] = val.map(mapFunction, context);
});