lodash#some JavaScript Examples
The following examples show how to use
lodash#some.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: utils.js From hzero-front with Apache License 2.0 | 7 votes |
/**
* todo 每次新增 tpl 都需要判断这里需不需要更改
* 能接收 tpl 作为 field 的组件 是否包含 child tpl
* @param {object} parent - 能接收 tpl 的 tpl
* @param {object} child - tpl
* @returns {boolean} parent 包含 child
*/
export function hasTemplate(parent, child) {
switch (parent.templateType) {
case 'DynamicTabs':
return some(parent.fields, field => {
return some(field.children, tpl => hasTemplate(tpl, child));
});
default:
return parent === child;
}
}
Example #2
Source File: DropFieldTabsTabPane.js From hzero-front with Apache License 2.0 | 6 votes |
DropFieldTabsTabPane = createDropField({
// 接收 左侧 tpl 组件
dropAcceptTypes: [DragType.dragComponent],
canDrop: props => {
const { currentEditField, currentEditComponent, component } = props;
// 只有当当前 TabPane 是 激活状态时 才能 拖入组件
return (
currentEditField === component ||
hasTemplate(some(component.children, child => hasTemplate(child, currentEditComponent)))
);
},
drop: (props, monitor) => {
// 如果在子组件中已经 drop 了, 这边就不需要继续 drop 了
if (!monitor.didDrop()) {
const { component } = props;
const { onAddField } = props;
if (isFunction(onAddField)) {
onAddField(component, monitor.getItem().component);
}
}
},
})
Example #3
Source File: index.jsx From mui-phone-input-ssr with MIT License | 5 votes |
constructor(props) {
super(props);
let filteredCountries = countryData.allCountries;
if (props.disableAreaCodes) filteredCountries = this.deleteAreaCodes(filteredCountries);
if (props.regions) filteredCountries = this.filterRegions(props.regions, filteredCountries);
const onlyCountries = this.excludeCountries(
this.getOnlyCountries(props.onlyCountries, filteredCountries), props.excludeCountries,
);
const preferredCountries = filter(filteredCountries, (country) => some(props.preferredCountries, (preferredCountry) => preferredCountry === country.iso2));
const inputNumber = props.value || '';
let countryGuess;
if (inputNumber.length > 1) {
// Country detect by value field
countryGuess = this.guessSelectedCountry(inputNumber.replace(/\D/g, '').substring(0, 6), onlyCountries, props.defaultCountry) || 0;
} else if (props.defaultCountry) {
// Default country
countryGuess = find(onlyCountries, { iso2: props.defaultCountry }) || 0;
} else {
// Empty params
countryGuess = 0;
}
const countryGuessIndex = findIndex(this.allCountries, countryGuess);
const dialCode = (
inputNumber.length < 2
&& countryGuess
&& !startsWith(inputNumber.replace(/\D/g, ''), countryGuess.dialCode)
) ? countryGuess.dialCode : '';
const formattedNumber = (inputNumber === '' && countryGuess === 0) ? ''
: this.formatNumber(
(props.disableCountryCode ? '' : dialCode) + inputNumber.replace(/\D/g, ''),
countryGuess.name ? countryGuess.format : undefined,
);
this.state = {
formattedNumber,
placeholder: props.placeholder,
onlyCountries,
preferredCountries,
defaultCountry: props.defaultCountry,
selectedCountry: countryGuess,
highlightCountryIndex: countryGuessIndex,
queryString: '',
freezeSelection: false,
debouncedQueryStingSearcher: debounce(this.searchCountry, 100),
anchorEl: null,
};
}
Example #4
Source File: index.jsx From mui-phone-input-ssr with MIT License | 5 votes |
MaterialUiPhoneNumber.defaultProps = {
excludeCountries: [],
onlyCountries: [],
preferredCountries: [],
defaultCountry: '',
placeholder: '+1 (702) 123-4567',
disabled: false,
error: false,
variant: 'standard',
native: false,
inputClass: '',
dropdownClass: '',
autoFormat: true,
disableAreaCodes: false,
isValid: (inputNumber) => some(countryData.allCountries, (country) => startsWith(inputNumber, country.dialCode) || startsWith(country.dialCode, inputNumber)),
disableCountryCode: false,
disableDropdown: false,
enableLongNumbers: false,
countryCodeEditable: true,
regions: '',
localization: {},
onEnterKeyPress: () => { },
onChange: () => { },
isModernBrowser: () => (document.createElement ? Boolean(document.createElement('input').setSelectionRange) : false),
keys: {
UP: 38,
DOWN: 40,
RIGHT: 39,
LEFT: 37,
ENTER: 13,
ESC: 27,
PLUS: 43,
A: 65,
Z: 90,
SPACE: 32,
},
};
Example #5
Source File: AccountInfo.js From hzero-front with Apache License 2.0 | 5 votes |
renderDefaultCompany() {
const { userInfo = {}, companyDataSource = [], form, updateCompanyLoading } = this.props;
const {
defaultCompanyProps: { editing = false },
} = this.state;
const curCompanyCanAssign = some(
companyDataSource,
company => company.companyId === userInfo.defaultCompanyId
);
let content;
const comment = intl
.get('hiam.userInfo.view.message.company')
.d('在汉得云平台内根据权限分配的公司中的默认公司选项');
const btns = [];
if (editing) {
// comment = '';
const companyOptions = map(companyDataSource, company => (
<Select.Option key={company.companyId} value={company.companyId}>
{company.companyName}
</Select.Option>
));
content = (
<>
{form.getFieldDecorator('defaultCompany', {
initialValue: curCompanyCanAssign ? userInfo.defaultCompanyId : undefined,
})(
<Select allowClear style={editWidthStyle}>
{companyOptions}
</Select>
)}
<Button style={btnStyle} onClick={this.handleDefaultCompanyEditCancel}>
{intl.get('hzero.common.button.cancel').d('取消')}
</Button>
<Button
type="primary"
style={btnStyle}
loading={updateCompanyLoading}
onClick={this.handleDefaultCompanyUpdate}
>
{intl.get('hzero.common.button.save').d('保存')}
</Button>
</>
);
} else {
content = curCompanyCanAssign ? userInfo.defaultCompanyName || '' : '';
btns.push(
<Button key="update" onClick={this.handleDefaultCompanyEdit}>
{intl.get('hzero.common.button.update').d('修改')}
</Button>
);
}
return (
<MaxLenItem
key="default-company"
itemIcon={null}
descriptions={intl.get('hiam.userInfo.model.user.defaultCompany').d('默认公司')}
content={content}
comment={comment}
btns={btns}
/>
);
}
Example #6
Source File: index.js From hzero-front with Apache License 2.0 | 5 votes |
/**
* 删除某一个 tabPane
*/
@Bind()
handleTabPaneRemove(tabPaneKey) {
const that = this;
const { component = {}, currentEditComponent, currentEditField } = that.props;
const { fields = [] } = component;
const nextFields = [];
let removeField;
forEach(fields, field => {
if (field.fieldName === tabPaneKey) {
removeField = field;
} else {
nextFields.push(field);
}
});
Modal.confirm({
content: `是否删除当前标签: ${removeField.fieldLabel}`,
onOk: () => {
component.fields = nextFields;
if (currentEditComponent === component) {
if (currentEditField === removeField) {
if (nextFields[0]) {
that.handleActiveField(nextFields[0]);
} else {
that.handleActiveTemplate();
}
return; // 删除 tabsTabPane 逻辑结束
}
} else if (
some(removeField.children, fieldC => hasTemplate(fieldC, currentEditComponent))
) {
if (nextFields[0]) {
that.handleActiveField(nextFields[0]);
} else {
that.handleActiveTemplate();
}
return; // 删除 tabsTabPane 逻辑结束
}
that.forceUpdate(); // 删除 tabsTabPane 逻辑结束
},
});
}