首页 \ 问答 \ 我需要backbone.js吗?(Is backbone.js necessary for me?)

我需要backbone.js吗?(Is backbone.js necessary for me?)

我正在开发一个webapp,最近我发现了backbone.js。 现在我正在开始一个新的应用程序,正在考虑学习backbone.js。 通过制作音乐播放器的3部分截屏教程,我只有1/3,而我的印象是模型和视图的设置非常混乱和乏味。 我正在开发PHP / Codeigniter框架,所以我想我已经知道MVC将如何帮助我。

但是,如果我想开发一个单页(多个标签)应用程序说,对于商店所有者来管理他们的库存,它可以使用显示仪表板,库存,供应,销售,助手,商店分支的选项卡。 如果没有backbone.js,jQuery的服务器端后端是不是足够了? jQuery可以隐藏显示不同的选项卡视图,处理UI元素的交互,发送和检索AJAX调用,管理模式对话框......当我可以使用数组时,为什么要使用集合和视图? 在这种情况下,使用backbone.js如何帮助开发此应用程序?


backbone.js has caught my interest recently as I was developing a webapp. Now I am starting a new app and is considering learning about backbone.js. I'm 1/3 of the way through a 3 part screencast tutorial on making a music player and my impressions are that the setting up of models and views were quite confusing and tedious. I am developing in PHP/Codeigniter framework so I guess I have an idea of how MVC will help me.

But if I want to develop an single page (multiple tabs) app say, for store owners to manage their inventory, it can uses tabs that shows Dashboard, Inventory, Supplies, Sales, Assistants, Store Branches. Wouldn't a serverside backend with jQuery be sufficient without backbone.js? jQuery can hide display the different tab views, handle the interaction of UI elements, send and retrieve AJAX calls, manage modal dialogs... Why should I use collections and views when I can use arrays? In this case, how will using backbone.js help in developing this app?


原文:https://stackoverflow.com/questions/10980210
更新时间:2022-09-03 08:09

最满意答案

首先,你需要修改你的php脚本

echo "<li><a class='clsPostData' data-sensorid='".$result['oxi_sensorid']."' data-apikey='".$result['oxi_apikey']."' href='#'>".$local."</a></li>";

和你的JQuery代码:

$(function(){
    $('.clsPostData').click(function(e){
          e.preventDefault();
          var objPost = {};
          objPost.api = $(this).data('apikey');
          objPost.sensor = $(this).data('sensorid');
          $.ajax({
             url: 'getData.php',
             type: 'post',
             data: objPost
          }).done(function(responseFromPhp){
             //Do something with the response, like
             alert(responseFromPhp.message);
          });
    });
});

你的getData.php脚本:

<?php
   $apikey = $_POST["api"];
   $sensorid = $_POST["sensor"];

   $response["message"] = "Grettings from php, we receive your sensorid: ".$sensorid;
   echo json_encode($response);
?>

First, you need to modify your php script:

echo "<li><a class='clsPostData' data-sensorid='".$result['oxi_sensorid']."' data-apikey='".$result['oxi_apikey']."' href='#'>".$local."</a></li>";

And your Jquery code:

$(function(){
    $('.clsPostData').click(function(e){
          e.preventDefault();
          var objPost = {};
          objPost.api = $(this).data('apikey');
          objPost.sensor = $(this).data('sensorid');
          $.ajax({
             url: 'getData.php',
             type: 'post',
             data: objPost
          }).done(function(responseFromPhp){
             //Do something with the response, like
             alert(responseFromPhp.message);
          });
    });
});

Your getData.php script:

<?php
   $apikey = $_POST["api"];
   $sensorid = $_POST["sensor"];

   $response["message"] = "Grettings from php, we receive your sensorid: ".$sensorid;
   echo json_encode($response);
?>

相关问答

更多
  • 在处理提交的文件中使用$_SERVER['HTTP_REFERER'] 。 Use $_SERVER['HTTP_REFERER'] in the file you process the submission.
  • 尝试添加jour图片作为标签的背景。 也适用于标签的样式。 a { width: 16.66%; height: 100px; display: block; background: url(your image URL); background-position: center; background-size: cover; background-repeat: none; } 背景尺寸:封面; 拉伸图像,直到它填满您的内容框。 您还可以使用不同 ...
  • 出来选择它: .page-header .menu li a.active, .page-header .menu li a.active:hover { background-color: white; font-weight: bold; color:black; } http://jsfiddle.net/userdude/RSwnP/ 注意,我已经添加了a.active:hover ,但是注意选择器特异性在这里覆盖了它。 看一下这个小提琴的例子(你可能想也可能不想用),其中 ...
  • 为menu提供宽度并使用margin: auto; #menu{ width:300px; <--------Here margin: 0 auto; <-----Here padding: 5px 0 0 0; list-style: none; background-color:#333333; text-align:center; } 而且你为什么要这样做? #menu li:hover > ul{ display: block; } 还有这 ...
  • 首先: #nav { display: table; width: 100%; } .alignright { float: right; } First of all: #nav { display: table; width: 100%; } .alignright { float: right; }
  • https://api.jquery.com/parent/ $(“li”)。parent(“。level3 dropdown-menu dynamic”)。addClass(“dropdown-submenu”); 是对的吗? Well, after some test with your code mHenderson, I finally got the answer! $(function () { $("ul.level3").parent("").addClass("d ...
  • 相关文章

    更多
  • Backbone.js的技巧和模式
  • js怎样获取所有windos对象?
  • JS URL编码函数
  • JS数据类型
  • js 缺少对象
  • js页面显示广告
  • FileUpload 对象 怎么用js 操作
  • VueJS与其他JS框架对比
  • 请教 JS 的 window open 问题
  • js问题 请大家帮看看
  • 最新问答

    更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)