当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript underscore.indexOf函数代码示例

本文整理汇总了TypeScript中underscore.indexOf函数的典型用法代码示例。如果您正苦于以下问题:TypeScript indexOf函数的具体用法?TypeScript indexOf怎么用?TypeScript indexOf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了indexOf函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: Error

				clusterEnrichment.run(data, argv.type, (result) => {
					if (argv.output) {
						fs.writeFile(argv.output, JSON.stringify(result, null, 2), (err) => {
							if (err) {
								process.stdout.write(`\x1b[31m=> Could not write to file ${argv.output}. \x1b[0m \n`);
							}
							else {
								console.log('=> Output written to file.');
							}
						});
					}
					if (argv.sort) {
						console.log(`=> Sorting by: ${argv.sort}`);
						try {
							let sort_key = argv.sort.split('.'),
								stage = _.indexOf(clusterEnrichment.clusterToStage, sort_key[0]);
							if (stage === -1) {
								throw new Error(`Not a valid cluster: ${sort_key}`);
							}
							sort_key[0] = 'data[' + stage + ']';
							result = utils.sort(result, sort_key.join('.'));
							utils.tabulate(result, ['label', sort_key.join('.')], console.log);
						}
						catch (e) {
							process.stdout.write(`\x1b[31m=> Sort failed: ${e.message}. \x1b[0m \n`);
						}
					}
					
					console.log('=> Done.');
				});			
开发者ID:delosh653,项目名称:SemNExT-Visualizations,代码行数:30,代码来源:main.ts

示例2: findPrevKey

    public findPrevKey (key: string): string {
        let i: number = _.indexOf(this.keys, key);

        if (i === 0 || i === -1) {
            return null;
        } else {
            return this.keys[i - 1];
        }
    }
开发者ID:CharlesXuuu,项目名称:mapillary-js,代码行数:9,代码来源:Sequence.ts

示例3: findNextKey

    public findNextKey (key: string): string {
        let i: number = _.indexOf(this.keys, key);

        if ((i + 1) >= this.keys.length || i === -1) {
            return null;
        } else {
            return this.keys[i + 1];
        }
    }
开发者ID:CharlesXuuu,项目名称:mapillary-js,代码行数:9,代码来源:Sequence.ts

示例4: logAnalyticsEvent

 private logAnalyticsEvent(elem: ValueElement, cause: IAnalyticsActionCause) {
   const strippedFacetValues = pluck(this.facetValues, 'value');
   elem.facet.usageAnalytics.logSearchEvent<IAnalyticsOmniboxFacetMeta>(cause, {
     query: this.omniboxObject.completeQueryExpression.word,
     facetId: elem.facet.options.id,
     facetTitle: elem.facet.options.title,
     facetValue: elem.facetValue.value,
     suggestions: strippedFacetValues.join(';'),
     suggestionRanking: indexOf(strippedFacetValues, elem.facetValue.value)
   });
 }
开发者ID:francoislg,项目名称:search-ui,代码行数:11,代码来源:OmniboxValuesList.ts

示例5: _toggle

    /**
     * Toggle the dropdown list.
     *
     * If the dropdown list doesn't fit below the dropdown label, this will
     * cause the dropdown to be dropped 'up'.
     */
    _toggle() {
        this.droplabel.blur();
        this.dropbutton.blur();

        if (this.droplist.classList.contains('mod-active')) {
            // Deselect active item.
            var active = this.droplist.querySelector('.mod-active');
            if (active) {
                active.classList.remove('mod-active');
            }
            // Close the drop list.
            this.droplist.classList.remove('mod-active');
            // Remove global keydown listener.
            document.removeEventListener('keydown', this.onKeydown);
            // Remove global mousedown listener.
            document.removeEventListener('mousedown', this.onDismiss);
            // Remove global scroll listener.
            window.removeEventListener('scroll', this.onDismiss);
            return;
        }

        // Add a global keydown listener for drop list events.
        document.addEventListener('keydown', this.onKeydown, true);
        // Add a global mousedown listener to dismiss drop list.
        document.addEventListener('mousedown', this.onDismiss, true);
        // Add a global scroll listener to dismiss drop list.
        window.addEventListener('scroll', this.onDismiss, true);

        // Set the currently selected item of the drop list.
        var value = this.model.get('value');
        var selectedIndex = _.indexOf(this.model.get('_options_labels'), value);
        if (selectedIndex > -1) {
            var items = this.droplist.querySelectorAll('.widget-dropdown-item');
            items[selectedIndex].classList.add('mod-active');
        }

        var buttongroupRect = this.buttongroup.getBoundingClientRect();
        var availableHeightAbove = buttongroupRect.top;
        var availableHeightBelow = window.innerHeight - buttongroupRect.bottom;
        var border = parseInt(getComputedStyle(this.droplist).borderWidth, 10);
        availableHeightAbove += border;
        availableHeightBelow -= border;
        var width = buttongroupRect.width;
        var maxHeight = Math.max(availableHeightAbove, availableHeightBelow);
        var top = 0;
        var left = buttongroupRect.left;

        this.droplist.style.left = Math.floor(left) + 'px';
        this.droplist.style.maxHeight = Math.floor(maxHeight) + 'px';
        this.droplist.style.width = Math.floor(width) + 'px';

        // Make drop list visible to compute its dimensions.
        this.droplist.classList.add('mod-active');

        var droplistRect = this.droplist.getBoundingClientRect();

        // If the drop list fits below, render below.
        if (droplistRect.height <= availableHeightBelow) {
            top = buttongroupRect.bottom + border;
            this.droplist.style.top = Math.ceil(top) + 'px';
        // If the drop list fits above, render above.
        } else if (droplistRect.height <= availableHeightAbove) {
            top = buttongroupRect.top - droplistRect.height + border;
            this.droplist.style.top = Math.floor(top) + 'px';
        // Otherwise, render in whichever has more space, above or below.
        } else if (availableHeightBelow >= availableHeightAbove) {
            top = buttongroupRect.bottom + border;
            this.droplist.style.top = Math.ceil(top) + 'px';
        } else {
            top = buttongroupRect.top - droplistRect.height + border;
            this.droplist.style.top = Math.floor(top) + 'px';
        }

        // If a selection is active, scroll to it if necessary.
        if (selectedIndex > -1) {
            scrollIfNeeded(this.droplist, items[selectedIndex]);
        }
    }
开发者ID:Lomascolo,项目名称:ipywidgets,代码行数:84,代码来源:widget_selection.ts

示例6: _handle_keydown

    /**
     * Handles keydown events for navigating the drop list.
     */
    _handle_keydown(event) {
        if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) {
            return;
        }

        // If some error condition has caused this listener to still be active
        // despite the drop list being invisible, remove all global listeners.
        if (!this.droplist.classList.contains('mod-active')) {
            document.removeEventListener('keydown', this.onKeydown);
            document.removeEventListener('mousedown', this.onDismiss);
            window.removeEventListener('scroll', this.onDismiss);
            return;
        }

        switch (event.keyCode) {
        case 13:  // Enter key
            event.preventDefault();
            event.stopPropagation();
            var active = this.droplist.querySelector('.mod-active');
            if (active) {
                var value = active.textContent;
                this.model.set('value', value, { updated_view: this });
                this.touch();
            }
            // Close the drop list.
            this._toggle();
            this.dropbutton.focus();
            return;
        case 27:  // Escape key
            event.preventDefault();
            event.stopPropagation();
            // Close the drop list.
            this._toggle();
            this.dropbutton.focus();
            return;
        case 38:  // Up arrow key
            event.preventDefault();
            event.stopPropagation();
            var active = this.droplist.querySelector('.mod-active');
            var items = this.droplist.querySelectorAll('.widget-dropdown-item');
            var index;
            if (active) {
                index = _.indexOf(items, active);
                index = Math.max(0, index - 1);
                active.classList.remove('mod-active');
            } else {
                // If there is no selection, up arrow selects the last item.
                index = items.length - 1;
            }
            items[index].classList.add('mod-active');
            scrollIfNeeded(this.droplist, items[index]);
            return;
        case 40:  // Down arrow key
            event.preventDefault();
            event.stopPropagation();
            var active = this.droplist.querySelector('.mod-active');
            var items = this.droplist.querySelectorAll('.widget-dropdown-item');
            var index;
            if (active) {
                index = _.indexOf(items, active);
                index = Math.min(items.length - 1, index + 1);
                active.classList.remove('mod-active');
            } else {
                // If there is no selection, down arrow selects the first item.
                index = 0;
            }
            items[index].classList.add('mod-active');
            scrollIfNeeded(this.droplist, items[index]);
            return;
        }
    }
开发者ID:Lomascolo,项目名称:ipywidgets,代码行数:74,代码来源:widget_selection.ts

示例7: parseMotion

export function parseMotion(tokens: string[]): Instruction | undefined {
    var commands = ['FORWARD', 'REVERSE', 'TURN_LEFT', 'TURN_RIGHT', 'STOP'];
    if (_.indexOf(commands, _.first(tokens)) !== -1) {
        return new MotionInstruction(_.first(tokens), _.rest(tokens));
    }
}
开发者ID:gsanta,项目名称:r0,代码行数:6,代码来源:parser.ts

示例8:

 var xxx = ()=> {
     var index = _.indexOf(months, month.toLowerCase());
     return index ? (zeroPad(index,2) + "-" + months[index]) : month;
 };
开发者ID:D10221,项目名称:SqLazy,代码行数:4,代码来源:helpers.ts

示例9:

 stateExists:function(stateName: any) {
   return _.indexOf(stateNames, stateName) > -1;
 },
开发者ID:prashanthc97,项目名称:kylo,代码行数:3,代码来源:AngularModuleExtensionService.ts

示例10: _toggle

    /**
     * Toggle the dropdown list.
     *
     * If the dropdown list doesn't fit below the dropdown label, this will
     * cause the dropdown to be dropped 'up'.
     */
    _toggle() {
        this.toggle.blur();

        if (this.droplist.classList.contains('mod-active')) {
            this._dismiss();
            return;
        }
        if (this.model.get('disabled')) {
            return;
        }

        this._add_droplist_events();
        // Set the currently selected item of the drop list.
        var value = this.model.get('value');
        var selectedIndex = _.indexOf(this.model.get('_options_labels'), value);
        if (selectedIndex > -1) {
            var items = this.droplist.querySelectorAll('.widget-dropdown-item');
            var selected = items[selectedIndex]
            selected.classList.add('mod-active', 'mod-selected');
            selected.insertBefore(this.check, selected.firstChild);
        }

        var buttongroupRect = this.toggle.getBoundingClientRect();
        var availableHeightAbove = buttongroupRect.top;
        var availableHeightBelow = window.innerHeight - buttongroupRect.bottom;
        var border = parseInt(getComputedStyle(this.droplist).borderWidth, 10);
        availableHeightAbove += border;
        availableHeightBelow -= border;
        var width = buttongroupRect.width;
        var maxHeight = Math.max(availableHeightAbove, availableHeightBelow);
        var top = 0;
        var left = buttongroupRect.left;

        this.droplist.style.left = Math.floor(left) + 'px';
        this.droplist.style.maxHeight = Math.floor(maxHeight) + 'px';
        this.droplist.style.width = Math.floor(width) + 'px';

        // Make drop list visible to compute its dimensions.
        this.droplist.classList.add('mod-active');
        var droplistRect = this.droplist.getBoundingClientRect();

        // If the drop list fits below, render below.
        if (droplistRect.height <= availableHeightBelow) {
            top = buttongroupRect.bottom;
            this.droplist.style.top = Math.ceil(top) + 'px';
            this.droplist.classList.add('below');
            this.droplist.classList.remove('above');
        // If the drop list fits above, render above.
        } else if (droplistRect.height <= availableHeightAbove) {
            top = buttongroupRect.top - droplistRect.height;
            this.droplist.style.top = Math.floor(top) + 'px';
            this.droplist.classList.remove('below');
            this.droplist.classList.add('above');
        // Otherwise, render in whichever has more space, above or below.
        } else if (availableHeightBelow >= availableHeightAbove) {
            top = buttongroupRect.bottom;
            this.droplist.style.top = Math.ceil(top) + 'px';
            this.droplist.classList.add('below');
            this.droplist.classList.remove('above');
        } else {
            top = buttongroupRect.top - droplistRect.height;
            this.droplist.style.top = Math.floor(top) + 'px';
            this.droplist.classList.remove('below');
            this.droplist.classList.add('above');
        }

        // If a selection is active, scroll to it if necessary.
        if (selectedIndex > -1) {
            scrollIfNeeded(this.droplist, items[selectedIndex]);
        }
    }
开发者ID:dmadeka,项目名称:ipywidgets,代码行数:77,代码来源:widget_selection.ts


注:本文中的underscore.indexOf函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。