gpt4 book ai didi

javascript - 使用 redux-orm 引导多对多关系

转载 作者:行者123 更新时间:2023-12-03 05:12:50 26 4
gpt4 key购买 nike

我有 Extent 的 aredux-orm 模型,如下所示:

const { string, number, arrayOf, oneOfType, instanceOf } = PropTypes

export default class Extent extends ValidatingModel {}

Extent.fields = {
xmin: attr(),
ymin: attr(),
xmax: attr(),
ymax: attr(),
zoomlevel: attr(),
tooltip: attr(),
tooltipDelay: attr(),
layers: many('Layer', 'extents'),
users: fk('User', 'extents')
}

Extent.propTypes = {
xmin: number,
ymin: number,
xmax: number,
ymax: number,
zoomlevel: number,
tooltip: string,
tooltipdelay: number,
layers: oneOfType([
arrayOf(number),
arrayOf(
instanceOf(Layer)
)
])
}

Extent.modelName = 'Extent'

我有相关的Layer模型,其定义如下:

const {
string,
number,
bool,
any,
oneOfType,
instanceOf
} = PropTypes

export default class Layer extends ValidatingModel {}

Layer.fields = {
objtype: fk('Bo', 'layers'),
layertype: attr(),
label: attr(),
layertypevalue: attr(),
geometrytype: attr(),
opacity: attr(),
token: attr(),
url: attr(),
readonly: attr(),
isFetching: attr(),
'default': fk('LayerConfiguration'),
status: attr(),
enabled: fk('LayerConfiguration', 'enabledLayers'),
highlighted: fk('LayerConfiguration', 'highlightedLayers'),
disabled: fk('LayerConfiguration', 'disabledLayers'),
filtered: fk('LayerConfiguration', 'filteredLayers'),
editing: fk('LayerConfiguration', 'editingLayers')
}

Layer.options = {
idAttribute: 'layerId'
}

我像这样引导他们的数据:

const victoriaExtent = Extent.create({
xmin: 144.776008,
ymin: -37.8458979,
xmax: 145.101998,
ymax: -37.6845001,
zoom: 15,
tooltip: 'Victoria',
tooltipDelay: 0
})

const transformer = Layer.create({
layerId: 1,
label: 'Transformer',
objtype: 'EQUI',
layertype: 'PLANPLANT',
layertypevalue: '0001',
geometrytype: 'Point',
opacity: 1,
token: null,
url: null,
readonly: false,
extents: [ victoriaExtent ],
status: 'default',
isFetching: false,
'default': null,
enabled: transformerEnabledConfig,
highlighted: highlightPointConfig,
disabled: transformerEnabledConfig,
filtered: transformerEnabledConfig,
editing: editingPointConfig
})

在该状态下,我发现关系并未填充,尽管它显示在 Layer 状态下有一个用于 extentsSessionBoundModelExtentsLayer 关系模型未填充数据。

此外,当我访问范围时,我发现 extent.layers 属性是未定义

最佳答案

我还不明白为什么,但我发现从另一方处理关系(这就是它的定义)会取得成果。我将引导更改为如下所示:

const victoriaExtent = Extent.create({
xmin: 144.776008,
ymin: -37.8458979,
xmax: 145.101998,
ymax: -37.6845001,
zoom: 15,
tooltip: 'Victoria',
tooltipDelay: 0,
user: spilli,
layers: [
transformer
]
})

当我在 layers 选择器中使用以下语句时,采用这种定义方式:

const layers = layerGroup.layers.toModelArray().map(layer => {
const obj2 = layer.ref
let enabled = layer.enabled
let extents

if (enabled && enabled.icon) {
const enabledRef = enabled.ref
const icon = enabled.icon.ref
enabled = Object.assign({}, enabledRef, { icon })
}

if (layer.extents) {
extents = layer.extents.toRefArray()
}

return Object.assign({}, obj2, { enabled, extents })
})

关于javascript - 使用 redux-orm 引导多对多关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41731718/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com