Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/439.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 把手类型错误:无法读取属性';fn';未定义的_Javascript_Node.js_Handlebars.js_Handlebarshelper_Zurb Ink - Fatal编程技术网

Javascript 把手类型错误:无法读取属性';fn';未定义的

Javascript 把手类型错误:无法读取属性';fn';未定义的,javascript,node.js,handlebars.js,handlebarshelper,zurb-ink,Javascript,Node.js,Handlebars.js,Handlebarshelper,Zurb Ink,我创建了一个自定义把手辅助对象,当我没有为参数定义值时,会出现以下错误 module.exports = function(src, color, classatr, options) { if (typeof src === 'undefined') src = ''; if (typeof color === 'undefined') color = ''; if (typeof classatr === 'undefined') classatr = '';

我创建了一个自定义把手辅助对象,当我没有为参数定义值时,会出现以下错误

module.exports = function(src, color, classatr, options) {

    if (typeof src === 'undefined') src = '';
    if (typeof color === 'undefined') color = '';
    if (typeof classatr === 'undefined') classatr = '';

    var bg = '<table class="'+ classatr +'" cellpadding="0" cellspacing="0" border="0" width="100%">\
      <tr>\
        <td background="'+ src +'" bgcolor="'+ color +'" valign="top">\
          <!--[if gte mso 9]>\
          <v:rect xmlns:v="urn:schemas-microsoft-com:vml" fill="true" stroke="false" style="mso-width-percent:1000;">\
            <v:fill type="tile" src="'+ src +'" color="#'+ color +'" />\
            <v:textbox style="mso-fit-shape-to-text:true" inset="0,0,0,0">\
          <![endif]-->\
          <div>'
          + options.fn(this) +
          '</div>\
          <!--[if gte mso 9]>\
            </v:textbox>\
          </v:rect>\
          <![endif]-->\
        </td>\
      </tr>\
    </table>';

    return bg;
}

可能尝试用null检查属性,而不是未定义的属性?

可能尝试用null检查属性,而不是未定义的属性?

如果不想提供任何参数,请使用
null
。因此,以下代码应该可以工作:

{{#bg-img null null null}}
    <container>
        <row>
            <columns>
            </columns>
        </row>
    </container>
{{/bg-img}}
{{{bg img null}
{{/bg img}}

在不想提供任何参数的地方使用
null
。因此,以下代码应该可以工作:

{{#bg-img null null null}}
    <container>
        <row>
            <columns>
            </columns>
        </row>
    </container>
{{/bg-img}}
{{{bg img null}
{{/bg img}}

您不应该在函数签名中声明可选参数。Handlebar将哈希对象放入传递给函数的提供选项对象中。通过hash对象,您可以访问所有提供的参数。请参阅中的“散列参数”部分


您不应该在函数签名中声明可选参数。Handlebar将哈希对象放入传递给函数的提供选项对象中。通过hash对象,您可以访问所有提供的参数。请参阅中的“散列参数”部分


有没有办法不用输入“null”我想没有。因为使用
null
可以告诉函数参数存在(表示其已定义),即使它不包含任何值。你不能用其他任何东西(如“未定义”)。因此,
null
是绕过实际提供任何参数的w/o的最佳方法。{{{{bg img'''''''}}就是这样做的。谢谢你的帮助。标记为答案。有没有办法不必输入“null”我认为没有。因为使用
null
可以告诉函数参数存在(表示其已定义),即使它不包含任何值。你不能用其他任何东西(如“未定义”)。因此,
null
是绕过实际提供任何参数的w/o的最佳方法。{{{{bg img'''''''}}就是这样做的。谢谢你的帮助。标记为应答。检查为空,未定义的错误仍然相同。仍然抛出相同的typeerror。已检查为null,未定义的仍然是相同的错误。还是吐出同样的打字错误。
if (typeof src === 'undefined' || src === null) src = '';
if (typeof color === 'undefined' || color === null) color = '';
if (typeof classatr === 'undefined' || classatr === null) classatr = '';
{{#bg-img null null null}}
    <container>
        <row>
            <columns>
            </columns>
        </row>
    </container>
{{/bg-img}}
module.exports = function(options) {

var src = options.hash.src;
var color = options.hash.color;
var classatr = options.hash.classatr;
if (typeof src === 'undefined') src = '';
if (typeof color === 'undefined') color = '';
if (typeof classatr === 'undefined') classatr = '';
...