【问题标题】:Passing a Blaze Template as a Parameter to a function creates Famous.js surface将 Blaze 模板作为参数传递给函数会创建 Famous.js 表面
【发布时间】:2015-09-07 02:30:27
【问题描述】:

我正在尝试使用 Meteor 的 Blaze.toHTMLWithData(template, data)(如 Blaze.toHTMLWithData(Template.roomIlanSpecsTemplate, data))来更新我的着名.js 表面的 content,并在函数中使用自定义模板在著名的 surface 内创建著名的 view。我想根据返回给其回调的文档类型在 cursorToArray 函数中传递模板。但是我无法在浏览器上呈现页面,即使控制台中没有错误。如果我使用硬编码版本,例如为每个不同的模板使用 createFn 函数,然后使用该函数定义和 cursorToArray 函数,它就可以工作。

我在这里想念什么?

    cursorToArray = function(cursor, renderablesArray, template, createFn){
    //each callback should decide which createFn to use based on result document, cos each result has a different template so a createFn.
    cursor.observe({
    addedAt: function(document, atIndex, before) {
        renderablesArray.splice(atIndex, 0, createFn(document, template));//createRoomIlanView, createRoomRenterIlanView, createFriendLookupIlanView
    },
    changedAt: function(newDocument, oldDocument, atIndex) {
        renderablesArray[atIndex] = createFn(newDocument, template);
    },
    });
}
cursorToArray(Ilans.find(), ilanViews, Template.roomIlanSpecsTemplate, createIlanView);

部分 createFn 定义:

function createIlanView(data, template){
        var ilanSpecsSurface = new Surface({
          content: Blaze.toHTMLWithData(template, data), 
          properties: {
            fontSize: "14px"
          }
        });

        return ilanSpecsSurface;
    }

【问题讨论】:

  • 在哪里将新的Surface 添加到FamousEngine 的上下文中
  • 我已经相应地编辑了标签。
  • 实际创建...函数创建一个famo.us view。 adn 添加了一些带有modifierssurfaces 的分支。上面的表面是这些支架尖端的表面之一,源于view
  • 这个视图用于填充一个数组,它作为我在 headerfooterlayout 的内容部分中使用的滚动视图的序列。
  • 我认为问题在于在表面的内容中传递Blaze 函数调用的参数。如果它像我在 Q 中所说的那样是硬编码的,它就可以工作; Blaze.toHTMLWithData(Template.roomIlanSpecsTemplate, data)。但我想简化它。

标签: meteor famo.us meteor-blaze


【解决方案1】:

如果都是关于旧的 Famous 怎么使用来自 https://stackoverflow.com/a/30445791/2288496 的 Reactive Surface

var ReactiveTemplate = famodev.ReactiveTemplate;


var reactive = new ReactiveTemplate({
   template: Template.mytemplate,
   data: Collection.find().fetch(),
   properties: {}
});

如何实现路由、订阅等的一个很好的例子https://github.com/sayawan/flowwy

【讨论】:

    猜你喜欢
    • 2015-09-22
    • 1970-01-01
    • 2018-09-28
    • 1970-01-01
    • 1970-01-01
    • 2015-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多