【问题标题】:dojox/mobile/Badge not rendered in custom ListItemdojox/mobile/Badge 未在自定义 ListItem 中呈现
【发布时间】:2016-10-23 14:39:21
【问题描述】:

这是我的自定义 ListItem 模板:

var template =
    "<div>" +
    "       <div style='display: inline;' data-dojo-attach-point='labelNode'></div>" +
    "       <div data-dojo-type='dojox/mobile/Badge' data-dojo-props='value:${size}' style='display: inline; position: absolute; right: 100px;'></div>" +
    "</div>";

正确创建了html,即:

<div data-dojo-type="dojox/mobile/Badge" data-dojo-props="value:37" style="display: inline; position: absolute; right: 100px;"></div>

但它在页面上不可见。 我尝试将完全相同的代码放在页面的其他位置,它可以工作。

更新

其他一些代码和信息。 我有一个dojox/mobile/EdgeToEdgeStoreList,我想使用我的自定义ListItem 而不是默认的。例如,我在一个属性上设置了background-color,我想用Badge 替换原来的rightText

这是CustomListItem的完整代码:

define([
    "dojox/mobile/ListItem",
    "dijit/_TemplatedMixin",
    "dojox/mobile/Badge",
    "dojo/_base/declare"
], function (ListItem, TemplatedMixin, Badge, declare) {
    var template =
        "<div class='areaDone${done}'>" +
        "       <div style='display: inline;' data-dojo-attach-point='labelNode'></div>" +
        "       <div data-dojo-type='dojox/mobile/Badge' data-dojo-props='value:${size}' style='display: inline; position: absolute; right: 100px;'></div>" +
        "</div>";

    TemplatedListItem = declare("CustomListItem",
        [ListItem, TemplatedMixin], {
            label: "My label",
            size: "0",
            templateString: template
        }
    );
});

这里是html(玉)代码:

h2(data-dojo-type="dojox.mobile.RoundRectCategory") List
    #panel(data-dojo-type="dojox/mobile/ScrollablePane")
        ul#list(data-dojo-type="dojox/mobile/EdgeToEdgeStoreList" data-dojo-props="itemRenderer: CustomListItem, itemMap: {Desc: 'label', size: 'size'}, select: 'single'")

最后是用来填充列表的js:

store = new Memory({data: JSON.parse(data), idProperty: "Desc"});
list.setStore(store);

【问题讨论】:

  • 您正在使用/创建小部件吗?你能发布一段你的 js/widget 的代码吗?
  • 我只是想在 EdgeToEdgeStoreList 中使用我的自定义 ListItem。我将在我的问题中添加一些其他代码。如果还不够,请询问!

标签: mobile dojo listitem badge


【解决方案1】:

您缺少从_WidgetsInTemplateMixin 扩展,这个mixin 告诉模板系统您的模板中有其他小部件,并在您的小部件被实例化时实例化它们。你可以read about it here

如何在代码中使用它的示例,请阅读 cmets:

define([
    "dojox/mobile/ListItem",
    "dijit/_TemplatedMixin",
    "dijit/_WidgetsInTemplateMixin", //Include this module
    "dojox/mobile/Badge",
    "dojo/_base/declare"
], function (ListItem, TemplatedMixin, _WidgetsInTemplateMixin, Badge, declare) {
    var template =
        "<div class='areaDone${done}'>" +
        "       <div style='display: inline;' data-dojo-attach-point='labelNode'></div>" +
        "       <div data-dojo-type='dojox/mobile/Badge' data-dojo-props='value:${size}' style='display: inline; position: absolute; right: 100px;'></div>" +
        "</div>";

    TemplatedListItem = declare("CustomListItem",
        [ListItem, TemplatedMixin, _WidgetsInTemplateMixin/*Extend*/], {
            label: "My label",
            size: "0",
            templateString: template
        }
    );
});

【讨论】:

  • 它就像一个魅力!我不明白模板mixin的作用。此外,我担心在为dojox 开发时包含dijit 组件,因此会造成混乱!
猜你喜欢
  • 2021-08-02
  • 1970-01-01
  • 2021-03-25
  • 1970-01-01
  • 1970-01-01
  • 2011-10-31
  • 2019-06-18
  • 1970-01-01
  • 2011-11-24
相关资源
最近更新 更多