【问题标题】:Populating the JSON Store data in Worklight 6.0在 Worklight 6.0 中填充 JSON 存储数据
【发布时间】:2013-12-01 15:17:39
【问题描述】:

我在显示推送到数据库的 JSON 存储数据时遇到问题。这是我的代码 sn-p 用于显示推送到服务器的 json 存储文档。

var _showTable = function (arr) {  

if (_.isArray(arr) && arr.length < 1) {  
return _logMessage(EMPTY_TABLE_MSG);  
}  

    //Log to the console  
        WL.Logger.ctx({stringify: true, pretty: true}).info(arr);  
        var  
    //Get reference to the status field  
        status = $('div#status-field'),  
    //Table HTML template  

    table = ['<table id="bu_table" >', 
        '<tr>',  
        '<td><b>JSON ID</b></td>',  
        '<td><b>BU NAME</b></td>',  
        '<td><b>BU DESC</b></td>',  
        '</tr>',  
    '<% _.each(bu, function(results) { %>',  
    '<tr>',  
    '<td> <%= results._id %> </td>',  
    '<td> <%= results.json.buname %> </td>',  
    '<td> <%= results.json.budesc %> </td>',  
    '</tr>',  
    '<% }); %>',  
    '</table>'  
    ].join(''),  
    //Populate the HTML template with content  
    html = _.template(table, {bu : arr});
    //Put the generated HTML table into the DOM  
    status.html(html);  
    };  

我正在尝试通过单击按钮来显示数据库中的文档。每次单击按钮时,整个文档都会附加到表格中,而不是替换。如何替换文档而不是每次单击按钮时都重复?

【问题讨论】:

  • 在重新填充之前清除表格肯定会有所帮助。你能分享你的代码的演示小提琴吗?

标签: underscore.js ibm-mobilefirst jsonstore


【解决方案1】:

在追加新数据之前清除表格。

$('div#status-field').empty();

【讨论】:

  • 它不工作.....我试过 //用内容填充 HTML 模板 html = _.template(table, {bu : arr}); $('div#status-field').empty(); //将生成的HTML表格放入DOM status.html(html);
【解决方案2】:

据我了解,status.html (html) 替换了整个内容,它不可能追加内容。

您是否确认“arr”变量仅包含您已经尝试显示的内容? (我想知道它是否只是比您预期的要多得多)。

最后,我对下划线不是很熟悉,但是“each”指令是否有可能生成这些重复项?

【讨论】:

    猜你喜欢
    • 2015-06-25
    • 2013-07-31
    • 1970-01-01
    • 1970-01-01
    • 2013-11-18
    • 2013-01-27
    • 1970-01-01
    • 2012-11-21
    • 2014-11-20
    相关资源
    最近更新 更多