TypeError:从proto类型读取时,此[_type]不是函数 [英] TypeError: this[_type] is not a function when read from proto type

查看:74
本文介绍了TypeError:从proto类型读取时,此[_type]不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用带有以下代码的json我使用它并产生一些对象,如文本框,复选框和...

我的json代码:

I use a json with below code for I use it and product some object like textbox,checkbox,and...
My json code:

var json = {
  TabPages: [{ ID: "tabPage1",Title: "test1233" , Left: 4, Top: 220, Height: 334, Width: 710 }], Data: { pidTextBox: 5 }, Components: [
                    {
                        ColumnName: "Pid",
                        Oridinal: true,
                        Controls: [
                            { Type: "label", Title: "Pid", Left: 24, Top: 20, Height: 13, Width: 130 },
                            { Type: "NumericTextBox", Name: "pidTextBox", Left: 160, Top: 20, Height: 21, Width: 100 },
                            { Type: "Checkbox", Name: "Chechbox", Left: 190, Top: 20, Height: 13, Width: 20 }

                        ]
                    },
                    {
                        ColumnName: "Plname",
                        ParentControl: "tabPage1",
                        Controls: [
                            { Type: "Label", Title: "Plname", Left: 24, Top: 70, Height: 13, Width: 130 },
                            { Type: "TextBox", Left: 160, Top: 70, Height: 21, Width: 200 },
                            { Type: "Checkbox", Name: "Chechbox", Left: 190, Top: 20, Height: 13, Width: 20 }
                        ]
                    }
                ]
            };

当我想使用它时,我们有这样的代码:

and when I want to use it,we have this code:

for (var i = 0, lnt = json.Components.length; i < lnt; ++i) {
                        for (var j = 0; j < json.Components[i].Controls.length; ++j) {
                            var _type = String(json.Components[i].Controls[j].Type).toLowerCase();
                            alert(_type);
                            alert([_type]);                                          
                            try {    this[_type](json.Components[i].Controls[j], json.Components[i]);
                                }
                                catch (e) {
                                    alert(e);
                                } 
    }
                    }  



i使用json.Components [i] .Controls [j] .Type类型和json .Components [i]换另一个词我有两个参数用于我的功能。





和设计对象的函数是:


i use json.Components[i].Controls[j].Type for type of it and json.Components[i] for another thig in another word I have two parameters for my function.


and functions for design object are:

window["f2form_" + "test"].prototype = {
              _initialize: function () {

              },

              textbox: function (params, colParams) {
                  params = params || {};
                  colParams = colParams || {};
                  var that = this;
                  alert(JSON.stringify(params));
                  var _input = GlobalUtilities.create_nested_elements([
                      {
                          Type: "input", Name: "_input", Style: "position:absolute; width:" + params.Width +
                              "px; top:" + params.Top + "px; " + LEFT + ":" + params.Left + "px; height:" + params.Height + "px",
                          Attributes: [{ Name: "type", Value: "text" }]
                      }
                  ], colParams.ParentControl ? that.Tabs[colParams.ParentControl] : that.ContainerDiv)["_input"];

                  that.cm[colParams.ColumnName] = { Get: function () { return _input.value; }, Set: function (val) { _input.value = val } }
              },and........



GlobalUtilities.create_nested_elements是GlobalUtilities对象中的方法,用于形成它。



我很困惑,因为原型中的函数名称与[_type]中为该函数发送参数的名称相同但我们有这个错误:

TypeError :这个[_type]不是一个函数

任何人都可以帮到我吗?


that GlobalUtilities.create_nested_elements is method in object of GlobalUtilities for made a shape of it.

I am confuse because the name of function in prototype is same to name in [_type] that send parameters for this function but we have this error:
TypeError: this[_type] is not a function
can anybody help to me?

推荐答案

这个[_type]成了这些你的样本

this[_type] is became on of these in your sample
this{"label"]
this{"NumericTextBox"]
this{"Checkbox"]



从您的代码中您已经声明了这些对象(它们存在,否则您应该得到) undefined 错误),但很明显它们不是函数类型的对象,你不能将它们用作函数...


Not clear from your code where you have declared these objects (they are exists, otherwise you should get undefined error), but it's clear that they are objects NOT of type of function, sou you can't use them as functions...

this[_type](json.Components[i].Controls[j], json.Components[i]);





我已在其他会话中回答了你的这个问题...



I already answered this question of yours on an other session...

window["f2form_" + "test"]



这是一个对象,但不是函数!!! br />
你必须在开始向它的原型添加东西之前添加这一行以确保你有一个功能...


This as an object, but not a function!!!
You have to add this line just before start adding things to it's prototype to ensure you have a function...

window["f2form_" + "test"] = new Function();



你可以使用new创建一个函数类型对象并运行它在原型上声明的函数...

还要处理你的信件案例 - JavaScript区分大小写...


Than you can create a function typed object using new and run it's functions declared on the prototype...
Also take care of your letter case - JavaScript is case sensitive...


这篇关于TypeError:从proto类型读取时,此[_type]不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆