你好我是require.js和backbone.js的新手我需要你帮助我的开发编程..
我的代码在:
的index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scaleable=no">
<link rel="stylesheet" href="css/jquery.mobile.structure-1.3.1.min.css" />
<link rel="stylesheet" href="css/themes/red.min.css" />
<link rel="stylesheet" href="css/menu.css" />
<link rel="stylesheet" href="css/table.css" />
<script>
curl = {
apiName: 'require'
};
</script>
<script src="js/libs/amd/require.js"></script>
<script src="js/bootstrap.js"></script>
</head>
<body>
<div data-add-back-btn="true" data-role="page" id="accountenquiry" data-url="/accountenquiry"> </div>
</body>
</html>
视图/帐户查询/ AccountEnquiryView.js
define([
'underscore',
'backbone',
'text!templates/account-enquiry/accountenquiry.html'
], function(_, Backbone, tmpl){
var serverUrl = 'http://localhost/agro-rib-mobile/restful/crud/get_all_accounts.php';
Account = Backbone.Model.extend({
urlRoot: serverUrl,
parse: function(response) {
console.log(response);
return response;
},
defaults: {
ACCOUNT_ID: null,
ACCOUNT_TYPE: '',
FULL_NAME: '',
ACCOUNT_NUMBER : '',
CURRENT_BALANCE: 0
}
});
var AccountCollection = Backbone.Collection.extend({
model:Account,
urlRoot: serverUrl,
parse: function(response) {
console.log(response);
return response;
}
});
var AccountEnquiryView = Backbone.View.extend({
el: '#accountenquiry',
template: _.template(tmpl),
initialize:function () {
console.log('Initializing Account Enquiry');
},
render: function() {
var AccountsCollection = Backbone.Collection.extend({
model : Account,
url: serverUrl,
parse: function(response) {
console.log(response);
return response;
}
});
var accounts = new AccountsCollection;
accounts.fetch();
//console.log(accounts.toJSON());
$(this.el).html(this.template(accounts.toJSON()));
return this;
}
});
return AccountEnquiryView;
});
模板/帐户查询/ accountenquiry.html
<!-- Start of second page: two -->
<div data-role="header">
<h1>Account Enquiry</h1>
</div><!-- /header -->
<div data-role="content" data-theme="a">
<p>All Account</p>
<table border="1" cellpadding="5" cellspacing="0" width="100%" class="ui-responsive" id="my-table" data-role="table" data-mode="columntoggle" >
<thead>
<tr>
<th width="50%">Account</th>
<th width="50%">Current Balance</th>
</tr>
</thead>
<tbody>
<% _.each(accounts, function(account) { %>
<tr>
<td>
<span><strong>Current Account(s)</strong></span><br>
<a class="detail" href="#/accountdisplay">
<%= account.FULL_NAME %> </a><br>
<span>19710257104</span>
</td>
<td>RM1,411,421,532</td>
</tr>
<% }); %>
</tbody>
</table>
</div>
为什么我收到此错误? ReferenceError {}
答案 0 :(得分:1)
已经修好了:)
define(['underscore', 'backbone', 'text!templates/account-enquiry/accountenquiry.html'], function(_, Backbone, tmpl) {
var serverUrl = 'http://localhost/agro-rib-mobile/restful/crud/get_all_accounts.php';
AccountModel = Backbone.Model.extend({});
var AccountCollection = Backbone.Collection.extend({
model: AccountModel,
urlRoot: serverUrl,
parse: function(response) {
return response;
}
});
var AccountEnquiryView = Backbone.View.extend({
el: '#accountenquiry',
initialize: function() {
},
render: function() {
var that = this;
this.collection = new AccountCollection();
this.collection.fetch({
success: function(collection, response) {
var template = _.template(tmpl, {
accounts: that.collection.models
});
that.$el.html(template);
},
error: function(collection, response) {
alert("error");
}
});
}
});
return AccountEnquiryView;
});