當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。