未捕获的TypeError:data.some不是函数

时间:2017-08-16 17:10:09

标签: javascript magento uncaught-typeerror

我正在试图找出我在Magento电子商务扩展中收到的JS错误,我付了很多钱,但是他们一直缺乏支持以解决这个问题。错误导致页面加载中的永久性旋转轮永远不会消失。

以下是我在开发者控制台中收到的错误:

Uncaught TypeError: data.some is not a function
at findFirst (select.js:67)
at UiClass.normalizeData (select.js:193)
at UiClass.normalizeData (wrapper.js:109)
at UiClass.getInitialValue (abstract.js:200)
at UiClass.setInitialValue (abstract.js:143)
at UiClass._super (wrapper.js:106)
at UiClass.setInitialValue (select.js:302)
at UiClass.setInitialValue (wrapper.js:109)
at UiClass.initialize (abstract.js:70)
at UiClass.initialize (wrapper.js:109)

这是select.js第67行的代码部分 data.some(函数(节点){错误引用:

/**
 * Recursively loops over data to find non-undefined, non-array value
 *
 * @param  {Array} data
 * @return {*} - first non-undefined value in array
 */
function findFirst(data) {
    var value;

    data.some(function (node) {
        value = node.value;

        if (Array.isArray(value)) {
            value = findFirst(value);
        }

        return !_.isUndefined(value);
    });

    return value;
}

我希望这只是某种错字错误,我可以自己解决?

提前感谢您的帮助。

P.S。我是编码新手。

3 个答案:

答案 0 :(得分:1)

在Magento 2.1.8中,删除了一个可能影响某些扩展的方法 - 它影响我们的名为getOptionArray()。

要在我们的扩展名中修复它:Ui / DataProvider / Product / Form / Modifier / FixedSelectionType.php

for j=1:1:10
    set_param('test_project/Pulse Generator','Period','j*2*pi');
    % do other things here...
end

成为:

'options' => FixedType::getOptionArray(),

并在model / attribute文件夹中添加此方法,在我们的示例中,完整路径为:Model / Attribute / Sources / FixedType.php

以及public函数getalloptions()方法上面添加:

'options' => FixedType::getOptionsArray(),

答案 1 :(得分:1)

在使用UI组件(特别是Select组件)创建表单时遇到了这个问题。我缺少了 caption 元素,因此,如果有人遇到此问题,他们可能会缺少一个元素。

<form>
...
<fieldset>
    ...
    <field name="select_example" formElement="select">
        <settings>
            <dataType>text</dataType>
            <label translate="true">Select Example</label>
            <dataScope>select_example</dataScope>
        </settings>
        <formElements>
            <select>
                <settings>
                    <options>
                        <option name="1" xsi:type="array">
                            <item name="value" xsi:type="string">1</item>
                            <item name="label" xsi:type="string">Option #1</item>
                        </option>
                        <option name="2" xsi:type="array">
                            <item name="value" xsi:type="string">2</item>
                            <item name="label" xsi:type="string">Option #2</item>
                        </option>
                        <option name="3" xsi:type="array">
                            <item name="value" xsi:type="string">3</item>
                            <item name="label" xsi:type="string">Option #3</item>
                        </option>
                    </options>
                    <caption translate="true">-- Please Select --</caption>
                </settings>
            </select>
        </formElements>
    </field>

答案 2 :(得分:0)

我在Magento 2.2.3版本中也遇到了这个问题。在文件vendor/magento/module-ui/view/base/web/js/form/element/select.js中发现了问题。 我们需要覆盖更改并将其添加到文件,如下所示。找到代码,

data.some(function (node) {
    value = node.value;

    if (Array.isArray(value)) {
        value = findFirst(value);
    }

    return !_.isUndefined(value);
}); 

替换为更新的代码,

data = _.some(data, function (node) {
    value = node.value;
    if (Array.isArray(value)) {
        value = findFirst(value);
    }

    return !_.isUndefined(value);
});  

这为我解决了这个问题。谢谢!