本文整理匯總了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);
});