0
Я использую backbone.js (AMD) и jquery mobile. У меня возникли проблемы с отображением данных на странице просмотра. Иногда страница html работает неправильно. Я могу что-то сделать, чтобы исправить мою проблему? Любые решения?Backbone.js - Как показать данные на странице просмотра?
courseModel
define(['underscore', 'backbone'], function(_, Backbone) {
var courseModel = Backbone.Model.extend({
});
return courseModel;
});
courseCollection
define(['underscore', 'backbone', 'model/course/courseModel'], function(_, Backbone, courseModel) {
var courseCollection = Backbone.Collection.extend({
model: courseModel,
url: "http://localhost:8888/impec-api/member/get_all_courses.php",
parse: function(data) {
return data.tbl_courses;
}
});
return courseCollection;
});
view.js
define(['jquery', 'underscore', 'backbone','model/course/courseCollection', 'text!modules/course/courseViewTemplate.html'], function($, _, Backbone, courseCollection,courseViewTemplate) {
var CourseView = Backbone.View.extend({
//initialize template
template:_.template(courseViewTemplate),
initialize: function() {
this.$el.off();
if (localStorage.studentId == null) {
window.location.replace("#login");
}
},
//render the content into div of view
render: function() {
var that = this;
this.collection = new courseCollection();
this.collection.fetch({
success: function(collection, response) {
that.$el.append(that.template({courses:that.collection.models}));
return that;
},
error: function(collection, response) {
alert("error");
}
});
return this;
}
});
return CourseView;
});
HTML
<div data-role="header">
<a href="#main">Back</a>
<h1>Course</h1>
</div>
<div data-role="content" >
<ul data-role="listview">
<% _.each(courses, function(course) { %>
<li><%= course.get('name') %></li>
<% }); %>
</ul>
</div>
выход
Большое спасибо заранее.
Вы должны улучшить ListView виджет с помощью '$ (« „) селектор. ListView (“ обновить») 'после цикла. – Omar
все тот же. , , –