Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.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
Templates 主干编辑模型_Templates_Backbone.js_Model_Field_Rounding - Fatal编程技术网

Templates 主干编辑模型

Templates 主干编辑模型,templates,backbone.js,model,field,rounding,Templates,Backbone.js,Model,Field,Rounding,我试图为我的问题找到一个简单的解决办法,但我做不到。 所以我有这样的模型: App.Models.Item = Backbone.Model.extend({ idAttribute: "ItemID", defaults: { ItemID: 1, TypeID: 1, Name: "", Price: 1.00,

我试图为我的问题找到一个简单的解决办法,但我做不到。 所以我有这样的模型:

App.Models.Item = Backbone.Model.extend({
    idAttribute: "ItemID",
    defaults:
            {
                ItemID: 1,
                TypeID: 1,
                Name: "",
                Price: 1.00,
                Image: "",
            },
    urlRoot: 'api/items'
});
在我的chtml文件中,我有以下内容:

<div class='wrapper'>  
    <a href="#" data-id ="<%= ItemID %>"><img src="data:image/png;base64,<%= Image %>" class="image"/></a>
    <div class ="price">
        <%= Price %>
    </div>
    <div class='description'>  
        <p class='description_content'><%= Name %></p>  
    </div>  
</div>

我只想编辑每个价格字段,使其有两个小数位。像数学之类的东西。。。但是我现在不知道如何用主干模型实现这个脚本。谢谢。

如果服务器返回的价格没有两位小数,您可以在parse方法中修复它。或者,您可以在模板中格式化输出:

<%= Price.toFixed(2) %>

你能提供将模型绑定到模板的视图吗?:-我用同样的方法尝试了,但显然我做错了什么。它起作用了!非常感谢。如果我需要用数学怎么办?像这样?