- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
这是一个完整的 Backbone.js 菜鸟问题。我正在尝试构建一个相当简单的单一应用程序界面的 ToDo Backbone.js 示例。 todo 项目更多的是关于用户输入,而这个应用程序更多的是关于根据用户选项(点击事件)过滤数据。
我对 Backbone.js 和 Mongoose 是全新的,一直无法找到一个很好的例子来说明我正在尝试做的事情。我已经能够让我的 api 从 MongoDB 集合中提取数据并将其放入 Backbone.js 集合中,该集合在应用程序中呈现它。我一生都无法弄清楚如何过滤该数据并重新呈现应用程序 View 。我正在尝试按文档中的“类型”字段进行过滤。
这是我的脚本:
(我完全知道需要进行一些重大重构,我只是在快速制作概念原型(prototype)。)
$(function() {
window.Job = Backbone.Model.extend({
idAttribute: "_id",
defaults: function() {
return {
attachments: false
}
}
});
window.JobsList = Backbone.Collection.extend({
model: Job,
url: '/api/jobs',
leads: function() {
return this.filter(function(job){ return job.get('type') == "Lead"; });
}
});
window.Jobs = new JobsList;
window.JobView = Backbone.View.extend({
tagName: "div",
className: "item",
template: _.template($('#item-template').html()),
initialize: function() {
this.model.bind('change', this.render, this);
this.model.bind('destroy', this.remove, this);
},
render: function() {
$(this.el).html(this.template(this.model.toJSON()));
this.setText();
return this;
},
setText: function() {
var month=new Array();
month[0]="Jan";
month[1]="Feb";
month[2]="Mar";
month[3]="Apr";
month[4]="May";
month[5]="Jun";
month[6]="Jul";
month[7]="Aug";
month[8]="Sep";
month[9]="Oct";
month[10]="Nov";
month[11]="Dec";
var title = this.model.get('title');
var description = this.model.get('description');
var datemonth = this.model.get('datem');
var dateday = this.model.get('dated');
var jobtype = this.model.get('type');
var jobstatus = this.model.get('status');
var amount = this.model.get('amount');
var paymentstatus = this.model.get('paymentstatus')
var type = this.$('.status .jobtype');
var status = this.$('.status .jobstatus');
this.$('.title a').text(title);
this.$('.description').text(description);
this.$('.date .month').text(month[datemonth]);
this.$('.date .day').text(dateday);
type.text(jobtype);
status.text(jobstatus);
if(amount > 0)
this.$('.paymentamount').text(amount)
if(paymentstatus)
this.$('.paymentstatus').text(paymentstatus)
if(jobstatus === 'New') {
status.addClass('new');
} else if (jobstatus === 'Past Due') {
status.addClass('pastdue')
};
if(jobtype === 'Lead') {
type.addClass('lead');
} else if (jobtype === '') {
type.addClass('');
};
},
remove: function() {
$(this.el).remove();
},
clear: function() {
this.model.destroy();
}
});
window.AppView = Backbone.View.extend({
el: $("#main"),
events: {
"click #leads .highlight" : "filterLeads"
},
initialize: function() {
Jobs.bind('add', this.addOne, this);
Jobs.bind('reset', this.addAll, this);
Jobs.bind('all', this.render, this);
Jobs.fetch();
},
addOne: function(job) {
var view = new JobView({model: job});
this.$("#activitystream").append(view.render().el);
},
addAll: function() {
Jobs.each(this.addOne);
},
filterLeads: function() {
// left here, this event fires but i need to figure out how to filter the activity list.
}
});
window.App = new AppView;
});
最佳答案
你试过了吗resetting包含“线索”过滤器结果的集合?
有点像
window.AppView = Backbone.View.extend({
el: $("#main"),
events: {
"click #leads .highlight" : "filterLeads"
},
initialize: function() {
Jobs.bind('add', this.addOne, this);
Jobs.bind('reset', this.render, this); //render on reset
Jobs.fetch(); //this triggers reset
},
addOne: function(job) {
var view = new JobView({model: job});
this.$("#activitystream").append(view.render().el);
},
//add a render function
render: function() {
this.$("#activitystream").empty(); //empty out anything thats in there
Jobs.each(this.addOne);
},
filterLeads: function() {
Jobs.reset(Jobs.leads()); //reset Jobs with only the leads
}
});
此外,您的 AppView 没有“渲染”方法,但您在此处引用它:
Jobs.bind('all', this.render, this);
关于javascript - 如何过滤 Backbone.js Collection 和 Rerender App View?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10955462/
据我所知,如果一个父组件重新渲染,那么它的所有子组件都会重新渲染,除非它们实现了 shouldComponentUpdate()。 .我 made an example这似乎不是真的。 我有 3 个组
我正在用 selenium 测试 Richfaces 应用程序。它工作正常,除非我使用 reRender . (对于那些不熟悉 Richfaces 的人 - 每当 ajax 请求完成时,部分 DOM
我正在尝试在我的应用程序 (Seam/RichFaces) 中显示购物车,并包含“从购物车中删除”旁边的每个项目以从购物车中删除该项目。当我单击该链接时,它应该重新呈现购物车内容以显示该项目已被删除。
我有一个 JSF 页面,我希望在该页面上有一个复选框,单击该复选框后,将从页面中添加/删除某些其他表单字段。这是我目前用于复选框的(简化)代码: 这是我要隐藏的组件的代码: 1 &
大家好, 故事时间 - 如果您不在乎,请跳过 我刚刚开始使用 Meteor + Polymer,使用 Synthesis作者:@aruntk,我对结果非常满意,也很感激他在这个项目上投入的时间。不过我
目前我正在开发一些复杂的 Web 前端并使用以下方法实现它: JSF 1.2 Facelets 1.1.15 RichFaces 3.3.3.Final 我创建了一个自定义 JSF 组件,它可以使用纯
我使用 rich:editor 来显示文件内容。如果我使用 h:commandlink 显示编辑器工作正常。如果我使用 a4j:commandlink 并重新渲染编辑器它不能正常工作。我得到以下脚本错
我有一个基于某些 boolean 条件呈现的 a4j:outputPanel: // bunch of stuff // 然后在同一个 .xhtml 页面上,我有一个下拉菜单,选择其中一个
我正在使用 OmniFaces FullAjaxExceptionHandler显示错误页面。错误页面显示正确,但这些页面的样式有问题。 我的应用程序使用的模板在 body 元素上定义了 CSS 类。
我有一个 react 应用程序,我在其中使用“react-image-pan-zoom-rotate”来显示图像。 https://github.com/mgorabbani/react-image-
我的问题是,我试图让数据表中的一列默认显示输出文本,并在按下命令按钮时将其替换为输入文本。还没有找到解决办法。顺便说一句,这是第一篇文章。 我有一个 a4j:commandButton,我希望重新渲染
我有一个 Richfaces listShuttle 组件,我需要对源值(左侧)进行排序。为此,在组件的值更改后,我有一个支持 bean 方法来对元素进行排序,并且我想重新呈现 listShuttle
在我的 JSF 页面上,我根据复选框的值显示一些内容。当重新渲染此内容时,如何附加效果(例如淡入和淡出)?是否有类似 onRender 之类的事件? 这是我到目前为止得到的,但效果没有显示:
我创建了这个测试用例来隔离我的问题。一旦轮询执行 ajax 更新,a4j:commandLink 操作就不会执行。如果我们在轮询的重新渲染之前关闭 modalPanel,它就会被执行。 有什么建议吗?
我有一个组件 Split,它有两个 child 。第一个 child 将显示在屏幕的左侧,第二个 child 将显示在屏幕的右侧。如果屏幕宽度低于某个点,则只会显示右侧,左侧将从 DOM 中移除。 示
我正在寻找有关如何处理此问题的规范引用。 如果我有一个看起来像这样的组件: const MyComponent = ({ value = [] }) => { const [otherValue,
我目前正在设计一个 MEAN.js Web 应用程序,由于某种原因,每当我在路由或 window.reload 上刷新页面时,它不会重新渲染页面,而只返回在当前找到的 JSON 文件路线。 例如,当我
我遇到了这个奇怪的问题,我可以弄清楚为什么会发生。 这种情况不应该发生,因为传递给 History 组件的 prop 尚未更新。 ./components/History.js ... const H
我是 React 新手,我将非常感谢任何帮助。我正在使用 create-react-app、react-router-dom 和express 服务器。当我尝试向博客文章(称为“详细信息”的子组件)提
当我在我的应用程序中导航时,我经常会遇到这个错误,这进一步破坏了我应用程序中的所有导航,我必须重新加载整个页面: Uncaught You can't call rerender on a view
我是一名优秀的程序员,十分优秀!