我有这个模型
var Item = Backbone.Model.extend({
url: 'http://localhost/InterprisePOS/Product/loaditembycategory/Event Materials'
});
var onSuccess = function(){ alert("success"); };
Run Code Online (Sandbox Code Playgroud)
还有一个系列
var Items = Backbone.Collection.extend({
model: Item
});
Run Code Online (Sandbox Code Playgroud)
其余的代码在这里:
var item = new Item();
var items = new Items();
item.fetch({ success: onSuccess });
alert(items.get("ItemCode"));
Run Code Online (Sandbox Code Playgroud)
我想要的是简单地获取模型的属性.现在我在萤火虫上有这个.此外,当我在浏览器上运行它时,我获得警报成功,并且下一个警报未定义.

这是输出:
{"ErrorMessage":null,"Items":[{"ErrorMessage":null,"CategoryCode":"Event Materials","ClassCode":null,"Components":null,"GroupCode":null,"ImageURL":null,"ItemCode":"ITEM-123","ItemDescription":"Old World Lamppost\u000d\u000a\u000d\u000a","ItemName":"GET123","ItemType":null,"KitItem":null,"Matrix":null,"Prefix":null,"RetailPrice":107.990000,"SalesTaxCode":null,"UPCCode":null,"UnitMeasureCode":"EACH","UnitsInStock":0,"Value":null,"WholesalePrice":95.000000}]}
Run Code Online (Sandbox Code Playgroud)
这只是它返回的项目之一.我刚刚发布了项目,所以它不会那么久.
我可以将我的模板放在单独的.html文件中,并在index.html中引用它们吗?
index.html:
<script type="text/template" id="item-list" src="item-list-tmpl.html"></script>
Run Code Online (Sandbox Code Playgroud)
item-list-tmpl.html:
<div><%= ItemDescription %><%= ItemCode %></div>
Run Code Online (Sandbox Code Playgroud)
我试过了,但问题是它没有在index.html上显示模板,但它加载到适当的位置(使用firebug查看)
找到了可能的解决方案,但不建议用于生产环境.
我在目标c中有这个错误
-fobjc-link-runtime它说找不到文件.我一直在谷歌搜索但未能得到导致错误的原因.我正在xcode4.5环境中构建它.使用ios6作为基础sdk.有任何想法吗?
这是在avassetwriter所写的帧上添加水印的方法吗?
根据我搜索过的内容,他们都假设该视频已经创建。如果在创建视频之前尚未创建视频,应该已经有水印了。那有可能吗?
谢谢
我想在我的视图模板中添加ID和CLASS属性.这是我尝试但失败的原因.
$("#login").html( _.template( LoginTemplate ) );
this.loginmodel = new LoginModel();
this.loginview = new LoginView({
el: $("#loginContainer"),
model: this.loginmodel,
className: "test"
});
<div id="loginContainer">
<div id="loginForm">
<input class="user-input formContainerInput" id="username" placeholder="Username" required="required"/>
<input class="user-input formContainerInput" id="password" type="password" placeholder="Password" required="required"/>
<a class="connection-btn" data-role="button">Connection</a>
<a class="login-btn" data-role="button">Log In</a>
</div>
Run Code Online (Sandbox Code Playgroud)
我想使用视图而不是html本身来分配id和class.我该怎么办?
尝试#1
loginview: function(){
$("#login").html( _.template( LoginTemplate ) );
this.loginmodel = new LoginModel();
this.loginview = new LoginView({
id: "#loginContainer",
model: this.loginmodel,
attributes:{ id:'Test', class: "myClass otherClass" }
});
},
Run Code Online (Sandbox Code Playgroud)
它甚至在"类"部分的aptana中显示错误.
甚至在主视图上尝试过,因为上面的代码是父视图.
var LoginView …Run Code Online (Sandbox Code Playgroud) 我需要覆盖Backbone.sync以允许PUT问题是我不知道如何以及在何处放置它.
这是我的模特:
define([
'underscore',
'backbone'
], function(_, Backbone) {
var Input = Backbone.Model.extend({
url: 'http://localhost/InterprisePOS/SOP/mobilecreateinvoice/',
initialize: function(){
},
toJSON : function() {
return _.clone({ input:this.attributes });
},
});
return Input;
});
Run Code Online (Sandbox Code Playgroud)
这是我视图中的保存功能:
save: function(){
invoice = new Invoice();
input = new Input();
invoice.set({POSWorkstationID: "POS7"});
invoice.set({POSClerkID: "admin"});
invoice.set({CustomerName: "Alice in Wonderland Tours"});
invoice.set({IsFreightOverwrite: true});
invoice.set({BillToCode: "CUST-000009"});
InvoiceCollection.add( invoice );
//var invoices = JSON.stringify({Invoices: InvoiceCollection.toJSON()});
_.each(this.collection.models, function(cart){
InvoiceDetailCollection.add( cart );
});
input.set({ "Invoices": InvoiceCollection.toJSON() });
input.set({ "InvoiceDetails": InvoiceDetailCollection});
alert( JSON.stringify(input.toJSON()) …Run Code Online (Sandbox Code Playgroud) 我如何比较骨干中的两个集合?
我有两个集合1C包含1,2,3虽然2C包含2,4,5我想要做的是2从2C 删除因为1C已经有一个值2后通常渲染集合.
我试过这个
this.1C.each(function(model1){
this.2C.each(function(model2){
if(model1 === model2){
2C.remove(model2);
}
});
});
Run Code Online (Sandbox Code Playgroud)
但它不起作用.有任何想法吗?
我有一个骨干系列和两个按钮.我想要做的是,如果我点击button1它应该按名称排序集合,如果点击button2它应按类别排序.
我试过这个
comparator : function(model){
return model.get("Name");
}
Run Code Online (Sandbox Code Playgroud)
我的问题是我的收藏中可以有两个比较器吗?我将如何分别按名称和类别对集合进行排序.有任何想法吗?谢谢
嗨我有一个集合和两个视图.在我的view1上我将数据添加到我的集合中,view2将只显示和显示有关集合的任何更改.但我无法让它发挥作用.问题是我原来是这样做的
return new CartCollection();
Run Code Online (Sandbox Code Playgroud)
但他们说这是一个不好的做法所以我删除改变它.但是当我在view1上实例化购物车集合时,它会添加,但似乎view2没有看到更改并且什么都不呈现.
有任何想法吗?
这是我的购物车系列.
define([
'underscore',
'backbone',
'model/cart'
], function(_, Backbone, CartModel) {
var CartCollection = Backbone.Collection.extend({
model : CartModel,
initialize: function(){
}
});
return CartCollection;
});
Run Code Online (Sandbox Code Playgroud)
这是我的itemView(view1)
AddToCart:function(ev){
ev.preventDefault();
//get data-id of the current clicked item
var id = $(ev.currentTarget).data("id");
var item = this.collection.getByCid(id);
var isDupe = false;
//Check if CartCollection is empty then add
if( CartCollection.length === 0){
CartCollection.add([{ItemCode:item.get("ItemCode"),ItemDescription:item.get("ItemDescription"),SalesPriceRate:item.get("RetailPrice"),ExtPriceRate:item.get("RetailPrice"),WarehouseCode: "Main",ItemType : "Stock",LineNum:1 }]);
}else{
//if check if the item to be added is already added, …Run Code Online (Sandbox Code Playgroud) backbone.js ×7
javascript ×5
objective-c ×2
requirejs ×2
ajax ×1
avfoundation ×1
ios ×1
jquery ×1
rest ×1