当我尝试显示从 Bootstrap 模态对话框中的集合获取的值时,我遇到了这个问题。
这是客户端javascript的代码:
Template.Modal_edit_client.edit_client_name = function() {
var c = Clients.findOne({_id: Session.get("current_editing")});
return c.name;
};
这是模板:
<template name="Modal_edit_client">
<div id="Modal_edit_client" class="modal hide fade">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3>Editar cliente</h3>
</div>
<div class="modal-body">
<form id="edit_client" action="">
<fieldset>
<input id="edit_client_name" placeholder="Nombre y apellido" type="text" value="{{edit_client_name}}">
{{edit_client_name}}
</fieldset>
</form>
</div>
<div class="modal-footer">
<a id="edit_client_cancel" href="#" class="btn">Cancelar</a>
<a id="edit_client_save" href="#" class="btn btn-primary">Guardar</a>
</div>
</div>
</template>
页面没有呈现,这是显示控制台的内容:
Uncaught TypeError: Cannot read property 'name' of undefined
Exception from Meteor.flush: TypeError: Cannot call method 'firstNode' of undefined
at Object.Spark.renderToRange (http://localhost:3000/packages/spark/spark.js?ba288278f8e36e3529187cea4590001f50ef0f95:545:25)
at http://localhost:3000/packages/spark/spark.js?ba288278f8e36e3529187cea4590001f50ef0f95:860:13
at http://localhost:3000/packages/deps/deps-utils.js?0c00e493224f891c3d6c82a23693ba55e0f47611:78:31
at _.extend.run (http://localhost:3000/packages/deps/deps.js?d804638a4633c2f6488827923ba5fbd00f07d518:19:20)
at rerun (http://localhost:3000/packages/deps/deps-utils.js?0c00e493224f891c3d6c82a23693ba55e0f47611:78:11)
at http://localhost:3000/packages/deps/deps.js?d804638a4633c2f6488827923ba5fbd00f07d518:71:15
at Array.forEach (native)
at Function._.each._.forEach (http://localhost:3000/packages/underscore/underscore.js?017a0dea6ebb07eec57a1541a0fd524665e769bd:79:11)
at http://localhost:3000/packages/deps/deps.js?d804638a4633c2f6488827923ba5fbd00f07d518:69:13
at Array.forEach (native) logging.js:30
Exception from Meteor.flush: TypeError: Cannot call method 'firstNode' of undefined
at Object.Spark.renderToRange (http://localhost:3000/packages/spark/spark.js?ba288278f8e36e3529187cea4590001f50ef0f95:545:25)
at http://localhost:3000/packages/spark/spark.js?ba288278f8e36e3529187cea4590001f50ef0f95:860:13
at http://localhost:3000/packages/deps/deps-utils.js?0c00e493224f891c3d6c82a23693ba55e0f47611:78:31
at _.extend.run (http://localhost:3000/packages/deps/deps.js?d804638a4633c2f6488827923ba5fbd00f07d518:19:20)
at rerun (http://localhost:3000/packages/deps/deps-utils.js?0c00e493224f891c3d6c82a23693ba55e0f47611:78:11)
at http://localhost:3000/packages/deps/deps.js?d804638a4633c2f6488827923ba5fbd00f07d518:71:15
at Array.forEach (native)
at Function._.each._.forEach (http://localhost:3000/packages/underscore/underscore.js?017a0dea6ebb07eec57a1541a0fd524665e769bd:79:11)
at http://localhost:3000/packages/deps/deps.js?d804638a4633c2f6488827923ba5fbd00f07d518:69:13
at Array.forEach (native) logging.js:30
Exception from Meteor.flush: TypeError: Cannot call method 'firstNode' of undefined
at Object.Spark.renderToRange (http://localhost:3000/packages/spark/spark.js?ba288278f8e36e3529187cea4590001f50ef0f95:545:25)
at http://localhost:3000/packages/spark/spark.js?ba288278f8e36e3529187cea4590001f50ef0f95:860:13
at http://localhost:3000/packages/deps/deps-utils.js?0c00e493224f891c3d6c82a23693ba55e0f47611:78:31
at _.extend.run (http://localhost:3000/packages/deps/deps.js?d804638a4633c2f6488827923ba5fbd00f07d518:19:20)
at rerun (http://localhost:3000/packages/deps/deps-utils.js?0c00e493224f891c3d6c82a23693ba55e0f47611:78:11)
at http://localhost:3000/packages/deps/deps.js?d804638a4633c2f6488827923ba5fbd00f07d518:71:15
at Array.forEach (native)
at Function._.each._.forEach (http://localhost:3000/packages/underscore/underscore.js?017a0dea6ebb07eec57a1541a0fd524665e769bd:79:11)
at http://localhost:3000/packages/deps/deps.js?d804638a4633c2f6488827923ba5fbd00f07d518:69:13
at Array.forEach (native)
我认为问题出现在第一行,Uncaught TypeError: Cannot read property 'name' of undefined。有没有办法等到 c.name !== undefined 之后再渲染模板?
最佳答案
当 meteor 第一次在浏览器上加载时,它的集合中没有来自服务器的任何数据,但模板仍会呈现。与未设置 session 时一样。所以你需要在加载时处理这个案例(在尝试读取 name
Template.Modal_edit_client.edit_client_name = function() {
var c = Clients.findOne({_id: Session.get("current_editing")});
if(c) return c.name;
};
关于mongodb - Bootstrap 模式对话框内的 meteor 模板渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15397913/
我有一个模型:classItem项目有一个属性“商店”基于存储的值,我希望Item对象对特定方法具有不同的行为。Rails中是否有针对此的通用设计模式?如果方法中没有大的if-else语句,这是如何干净利落地完成的? 最佳答案 通常通过Single-TableInheritance. 关于ruby-on-rails-Rails-子类化模型的设计模式是什么?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.co
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
我有一个ModularSinatra应用程序,我正在尝试将Bootstrap添加到应用程序中。get'/bootstrap/application.css'doless:"bootstrap/bootstrap"end我在views/bootstrap中有所有less文件,包括bootstrap.less。我收到这个错误:Less::ParseErrorat/bootstrap/application.css'reset.less'wasn'tfound.Bootstrap.less的第一行是://CSSReset@import"reset.less";我尝试了所有不同的路径格式,但它
我正在使用puppet为ruby程序提供一组常量。我需要提供一组主机名,我的程序将对其进行迭代。在我之前使用的bash脚本中,我只是将它作为一个puppet变量hosts=>"host1,host2"我将其提供给bash脚本作为HOSTS=显然这对ruby不太适用——我需要它的格式hosts=["host1","host2"]自从phosts和putsmy_array.inspect提供输出["host1","host2"]我希望使用其中之一。不幸的是,我终其一生都无法弄清楚如何让它发挥作用。我尝试了以下各项:我发现某处他们指出我需要在函数调用前放置“function_”……这
鉴于我有以下迁移:Sequel.migrationdoupdoalter_table:usersdoadd_column:is_admin,:default=>falseend#SequelrunsaDESCRIBEtablestatement,whenthemodelisloaded.#Atthispoint,itdoesnotknowthatusershaveais_adminflag.#Soitfails.@user=User.find(:email=>"admin@fancy-startup.example")@user.is_admin=true@user.save!ende
给定一个复杂的对象层次结构,幸运的是它不包含循环引用,我如何实现支持各种格式的序列化?我不是来讨论实际实现的。相反,我正在寻找可能会派上用场的设计模式提示。更准确地说:我正在使用Ruby,我想解析XML和JSON数据以构建复杂的对象层次结构。此外,应该可以将该层次结构序列化为JSON、XML和可能的HTML。我可以为此使用Builder模式吗?在任何提到的情况下,我都有某种结构化数据-无论是在内存中还是文本中-我想用它来构建其他东西。我认为将序列化逻辑与实际业务逻辑分开会很好,这样我以后就可以轻松支持多种XML格式。 最佳答案 我最
我们目前正在为ROR3.2开发自定义cms引擎。在这个过程中,我们希望成为我们的rails应用程序中的一等公民的几个类类型起源,这意味着它们应该驻留在应用程序的app文件夹下,它是插件。目前我们有以下类型:数据源数据类型查看我在app文件夹下创建了多个目录来保存这些:应用/数据源应用/数据类型应用/View更多类型将随之而来,我有点担心应用程序文件夹被这么多目录污染。因此,我想将它们移动到一个子目录/模块中,该子目录/模块包含cms定义的所有类型。所有类都应位于MyCms命名空间内,目录布局应如下所示:应用程序/my_cms/data_source应用程序/my_cms/data_ty
我正在使用Mandrill的RubyAPIGem并使用以下简单的测试模板:testastic按照Heroku指南中的示例,我有以下Ruby代码:require'mandrill'm=Mandrill::API.newrendered=m.templates.render'test-template',[{:header=>'someheadertext',:main_section=>'Themaincontentblock',:footer=>'asdf'}]mail(:to=>"JaysonLane",:subject=>"TestEmail")do|format|format.h
所以这可能有点令人困惑,但请耐心等待。简而言之,我想遍历具有特定键值的所有属性,然后如果值不为空,则将它们插入到模板中。这是我的代码:属性:#===DefaultfileConfigurations#default['elasticsearch']['default']['ES_USER']=''default['elasticsearch']['default']['ES_GROUP']=''default['elasticsearch']['default']['ES_HEAP_SIZE']=''default['elasticsearch']['default']['MAX_OP
了解Rails缓存如何工作的人可以真正帮助我。这是嵌套在Rails::Initializer.runblock中的代码:config.after_initializedoSomeClass.const_set'SOME_CONST','SOME_VAL'end现在,如果我运行script/server并发出请求,一切都很好。然而,在我的Rails应用程序的第二个请求中,一切都因单元化常量错误而变得糟糕。在生产模式下,我可以成功发出第二个请求,这意味着常量仍然存在。我已通过将以上内容更改为以下内容来解决问题:config.after_initializedorequire'some_cl