FeatureFormViewModel

AMD: require(["geoscene/widgets/FeatureForm/FeatureFormViewModel"], (FeatureFormVM) => { /* code goes here */ });
ESM: import FeatureFormVM from "@geoscene/core/widgets/FeatureForm/FeatureFormViewModel.js";
类: geoscene/widgets/FeatureForm/FeatureFormViewModel
继承于:FeatureFormViewModel Accessor
起始版本:GeoScene Maps SDK for JavaScript 4.9

提供 FeatureForm 微件的逻辑。

已知限制

此微件尚无法完全与 3.x AttributeInspector 微件提供的功能相等。尽管可以通过 Editor 微件编辑附件和关系数据,但目前不支持仅在此微件中编辑附件或相关记录。有关此方面的任何已知限制,请参阅 Editor 文档。

另请参阅
示例
let featureForm = new FeatureForm({
  viewModel: { // Autocasts as new FeatureFormViewModel()
    map: map, // Required if using Arcade expressions that use the global $map variable
    layer: featureLayer   // Associates the FeatureForm to the layer
  },
  container: "formDiv"
});

构造函数

new FeatureFormViewModel(properties)
参数
properties Object
optional

有关可能传递给构造函数的所有属性的列表,请参见属性

属性概述

所有属性都可以设置、获取和监听。请参阅使用属性主题。
显示继承属性 隐藏继承属性
名称 类型 描述
String

类的名称。

更多详情
Accessor
Graphic

包含可编辑属性的关联要素。

更多详情
FeatureFormViewModel
FormTemplate

用于表单的关联 template

更多详情
FeatureFormViewModel
Array<(InputField|InputFieldGroup)>

组成表单 FeatureForm 微件的字段或组输入。

更多详情
FeatureFormViewModel
Array<(FieldInput|GroupInput|RelationshipInput)>

组成表单 FeatureForm 微件的字段、组或关系输入。

更多详情
FeatureFormViewModel
FeatureLayer|SceneLayer|SubtypeSublayer

包含可编辑要素属性的图层。

更多详情
FeatureFormViewModel
Map

对关联 Map 的引用。

更多详情
FeatureFormViewModel
String

微件的状态。

更多详情
FeatureFormViewModel
Boolean

指示是否可以在不引入数据验证问题的情况下提交字段的值。

更多详情
FeatureFormViewModel
Boolean

指示表单当前是否正在更新。

更多详情
FeatureFormViewModel
Boolean

指示是否所有输入字段都有效。

更多详情
FeatureFormViewModel

属性详细信息

declaredClass Stringreadonly inherited

类的名称。声明的类名称格式化为 geoscene.folder.className

feature Graphic

包含可编辑属性的关联要素。访问它的常用方法是通过 MapViewSceneViewhitTest() 方法。

示例
// Check if a user clicked on an incident feature.
view.on("click", function(event) {
  view.hitTest(event).then(function(response) {
    // Display the attributes of selected incident feature in the form
    if (response.results[0].graphic && response.results[0].graphic.layer.id == "incidentsLayer") {
       formVM.feature = result.results[0].graphic
    }
  });
});
起始版本:GeoScene Maps SDK for JavaScript 4.16

用于表单的关联 template

formTemplate 中,您可以配置表单的显示方式,并设置表单的任何关联属性,例如标题、说明、字段元素等。

另请参阅
inputFields Array<(InputField|InputFieldGroup)>readonly
从 4.27 版开始已弃用。请改为使用输入。

组成表单 FeatureForm 微件的字段或组输入。

起始版本:GeoScene Maps SDK for JavaScript 4.27

组成表单 FeatureForm 微件的字段、组或关系输入。

包含可编辑要素属性的图层。如果未指定此图层,则它与图形图层相同。

map Map
起始版本:GeoScene Maps SDK for JavaScript 4.27

对关联 Map 的引用。

如果在 FeatureForm 中使用了 $map 全局变量的Arcade 表达式,则需要此属性。

state Stringreadonly

微件的状态。下表列出了可能的值。

描述
ready 满足依赖关系并具有有效的属性值。
disabled 依赖项丢失,无法提供有效的输入。

可能的值"ready"|"disabled"

默认值:disabled
submittable Boolean

指示是否可以在不引入数据验证问题的情况下提交字段的值。

updating Booleanreadonly
起始版本:GeoScene Maps SDK for JavaScript 4.27

指示表单当前是否正在更新。

valid Booleanreadonly

指示是否所有输入字段都有效。

方法概述

显示继承的方法 隐藏继承的方法
名称 返回值类值 描述

添加一个或多个与对象生命周期相关联的句柄

更多详情
Accessor
Boolean

在实例上触发事件。

更多详情
FeatureFormViewModel
FieldInput

查找字段输入的便捷方法。

更多详情
FeatureFormViewModel
Object

返回所有字段值,无论它们是否已更新。

更多详情
FeatureFormViewModel
Boolean

指示实例上是否存在与提供的事件名称相匹配的事件监听器。

更多详情
FeatureFormViewModel
Boolean

如果存在指定的句柄组,则返回 true。

更多详情
Accessor
Object

在实例上注册事件处理程序。

更多详情
FeatureFormViewModel

移除对象拥有的句柄组。

更多详情
Accessor

该方法用于设置更新的字段值。

更多详情
FeatureFormViewModel

触发 submit 事件。

更多详情
FeatureFormViewModel
Object[]

验证要素的属性值是否符合定义的偶然值。

更多详情
FeatureFormViewModel

方法详细说明

addHandles(handleOrHandles, groupKey)inherited
起始版本:GeoScene Maps SDK for JavaScript 4.25

添加一个或多个与对象的生命周期相关联的句柄。当对象被销毁时,将移除句柄。

// Manually manage handles
const handle = reactiveUtils.when(
  () => !view.updating,
  () => {
    wkidSelect.disabled = false;
  },
  { once: true }
);

this.addHandles(handle);

// Destroy the object
this.destroy();
参数
handleOrHandles WatchHandle|WatchHandle[]

对象销毁后,标记为要移除的句柄。

groupKey *
optional

标识句柄应添加到的组的键。组中的所有句柄稍后都可使用 Accessor.removeHandles() 进行删除。如果未提供键,则句柄将被添加到默认组。

emit(type, event){Boolean}

在实例上触发事件。仅当创建此类的子类时,才应使用此方法。

参数
type String

事件的名称。

event Object
optional

事件有效负载。

返回
类型 描述
Boolean true 如果监听器收到通知,则为
findField(fieldName){FieldInput}

查找字段输入的便捷方法。

参数
fieldName String

要查找的输入字段。

返回
类型 描述
FieldInput 返回 FieldInput 的实例。
getValues(){Object}

返回所有字段值,无论它们是否已更新。

返回
类型 描述
Object 字段名称及其值的键值对的对象。
另请参阅
示例
function updateFeature() {
  // Get the updated field values
  const attributes = formVM.getValues();
  // Call applyEdits on the feature layer
  layer.applyEdits({
    // Pass in the updated field values
    updateFeatures: [{ attributes }]
  });
}
hasEventListener(type){Boolean}

指示实例上是否存在与提供的事件名称相匹配的事件监听器。

参数
type String

事件的名称。

返回
类型 描述
Boolean 如果类支持输入事件,则返回 true。
hasHandles(groupKey){Boolean}inherited
起始版本:GeoScene Maps SDK for JavaScript 4.25

如果存在指定的句柄组,则返回 true。

参数
groupKey *
optional

组键。

返回
类型 描述
Boolean 如果存在指定的句柄组,则返回 true
示例
// Remove a named group of handles if they exist.
if (obj.hasHandles("watch-view-updates")) {
  obj.removeHandles("watch-view-updates");
}
on(type, listener){Object}

在实例上注册事件处理程序。调用此方法将事件与监听器挂钩。

参数

要监听的事件或事件数组。

listener Function

事件触发时要调用的函数。

返回
类型 描述
Object 返回一个具有 remove() 方法的事件处理程序,应该调用该方法以停止监听事件。
属性 类型 描述
remove Function 当调用时,将从事件中移除该监听器。
示例
view.on("click", function(event){
  // event is the event handle returned after the event fires.
  console.log(event.mapPoint);
});
removeHandles(groupKey)inherited
起始版本:GeoScene Maps SDK for JavaScript 4.25

移除对象拥有的句柄组。

参数
groupKey *
optional

要移除的组键或组键的数组或集合。

示例
obj.removeHandles(); // removes handles from default group

obj.removeHandles("handle-group");
obj.removeHandles("other-handle-group");
setValue(fieldName, value)
起始版本:GeoScene Maps SDK for JavaScript 4.21

该方法用于设置更新的字段值。

这将在表单中渲染新值,但不会更新基础输入要素的属性。

参数
fieldName String

要更新的目标字段。

要在目标字段上设置的值。

submit()

触发 submit 事件。

示例
// Listen for when 'submit' is called.
// Once it is fired, update the feature.
formVM.on("submit", updateFeature);

// When the DOM's button (btnUpdate) is clicked,
// Update attributes of the selected feature.
document.getElementById("btnUpdate").onclick = function() {
  // Fires feature form's submit event.
  formVM.submit();
}
validateContingencyConstraints(values, options){Object[]}
起始版本:GeoScene Maps SDK for JavaScript 4.23

验证要素的属性值是否符合定义的偶然值。

参数
values String

表单字段及其值的哈希映射

options Object
optional

一个对象,指定了应被视为错误的其他选项。

规范
includeIncompleteViolations Boolean
optional

如果为 true,则返回字段组的意外冲突,这些字段组由于尚未为其所有字段指定值而无效。如果为 false,则忽略这些违规行为。

返回
类型 描述
Object[] 对象数组,每个对象表示违反字段组的条件值规则
示例
// Validate a features attribute values against the layer's contingent values
featureForm.on("value-change", () => {
  const validations = featureForm.viewModel.validateContingencyConstraints(featureForm.getValues());
  !!validations.length ? console.log("found some validation errors: ", validations) : console.log("no errors found!");
});

事件概述

名称 类型 描述
{valid: String[],invalid: String[],values: Object}

当调用 submit() 方法时触发。

更多详情
FeatureFormViewModel
{layer: FeatureLayer,feature: Graphic,fieldName: String,value: Number|String|null,valid: Boolean}

在更新字段值时触发。

更多详情
FeatureFormViewModel

事件详细说明

submit

当调用 submit() 方法时触发。调用 FeatureLayer.applyEdits() 方法来更新要素的属性。

属性
valid String[]

有效的字段名称。

invalid String[]

无效的字段名称。

values Object

字段名称的键值对对象及其所有值,无论它们是否已更新。

另请参阅
示例
// Listen for the submit event.
featureFormVM.on("submit", function(){
  if (editFeature) {
    // Grab updated attributes from the form.
    const updated = featureFormVM.getValues();

    // Loop through updated attributes and assign
    // the updated values to feature attributes.
    Object.keys(updated).forEach(function(name) {
      editFeature.attributes[name] = updated[name];
    });

    // Setup the applyEdits parameter with updates.
    const edits = {
      updateFeatures: [editFeature]
    };
    applyEdits(edits);
  }
});
value-change

在更新字段值时触发。

属性

关联的要素图层。

feature Graphic

关联的要素

fieldName String

更新的字段。

更新的字段值。

valid Boolean

如果为 true,则该值符合字段的定义。

您的浏览器不再受支持。请升级您的浏览器以获得最佳体验。