我有一个嵌套的视图设置,可以在我的应用程序中得到一些深度.有很多方法我可以想到初始化,渲染和追加子视图,但我想知道常见的做法是什么.
这是我想到的一对夫妇:
initialize : function () {
this.subView1 = new Subview({options});
this.subView2 = new Subview({options});
},
render : function () {
this.$el.html(this.template());
this.subView1.setElement('.some-el').render();
this.subView2.setElement('.some-el').render();
}
Run Code Online (Sandbox Code Playgroud)
优点:您不必担心通过追加维护正确的DOM顺序.视图在早期初始化,因此在渲染函数中不会同时执行所有操作.
缺点:你被迫重新委托事件(),这可能是昂贵的?父视图的渲染函数与所有需要发生的子视图渲染混杂在一起?您无法设置tagName元素,因此模板需要维护正确的tagNames.
其他方式:
initialize : function () {
},
render : function () {
this.$el.empty();
this.subView1 = new Subview({options});
this.subView2 = new Subview({options});
this.$el.append(this.subView1.render().el, this.subView2.render().el);
}
Run Code Online (Sandbox Code Playgroud)
优点:您无需重新委派活动.您不需要仅包含空占位符的模板,并且您的tagName将返回由视图定义.
缺点:您现在必须确保以正确的顺序附加内容.子视图渲染仍然使父视图的渲染变得混乱.
有一个onRender事件:
initialize : function () {
this.on('render', this.onRender);
this.subView1 = new Subview({options});
this.subView2 = new Subview({options});
},
render : …Run Code Online (Sandbox Code Playgroud) 我在MVC视图上有以下字段:
@Html.TextBoxFor(model => model.Course.Title, new { data_helptext = "Old Text" })</span>
Run Code Online (Sandbox Code Playgroud)
在单独的js文件中,我想将data-helptext属性设置为字符串值.这是我的代码:
alert($(targetField).data("helptext"));
$(targetField).data("helptext", "Testing 123");
Run Code Online (Sandbox Code Playgroud)
该alert()呼叫工作正常,它显示在警报对话框文本"古文字".但是,将data-helptext属性设置为"测试123" 的调用不起作用."旧文本"仍然是属性的当前值.
我是否错误地使用了对data()的调用?我在网上看了这个,我看不出我做错了什么.
这是HTML标记:
<input data-helptext="Old Text" id="Course_Title" name="Course.Title" type="text" value="" />
Run Code Online (Sandbox Code Playgroud) model-view-controller jquery attributes custom-data-attribute
对我的应用程序使用的各种视图使用单独的样式表的正确/可接受的方法是什么?
目前我在顶部的view/partial的html中放置一个链接元素,但我被告知这是不好的做法,即使所有现代浏览器都支持它,但我可以看到为什么它不赞成.
另一种可能性是将单独的样式表放在我的index.html中,head但是如果它的视图以性能名称加载,我希望它只加载样式表.
这是不好的做法,因为直到从服务器加载css之后样式才会生效,导致在慢速浏览器中快速刷新未格式化的内容?虽然我正在本地测试它,但我还没有见证这一点.
有没有办法通过传递给Angular的对象加载CSS $routeProvider.when?
提前致谢!
我正在练习MVC风格的编程.我在一个文件中有一个Mastermind游戏,工作正常(可能除了"Check"按钮在开始时不可见).
http://paste.pocoo.org/show/226726/
但是当我把它重写为模型,视图,控制器文件时 - 当我点击空Pin(应该更新,并重新绘制新颜色)时 - 注意到了.谁能在这里看到任何问题?我尝试在不同的地方放置repaint(),但它根本不起作用:/
主要:
public class Main {
public static void main(String[] args){
Model model = new Model();
View view = new View("Mastermind", 400, 590, model);
Controller controller = new Controller(model, view);
view.setVisible(true);
}
}
Run Code Online (Sandbox Code Playgroud)
型号:
import java.util.Random;
public class Model{
static final int
LINE = 5,
SCORE = 10, OPTIONS = 20;
Pin pins[][] = new Pin[21][LINE];
int combination[] = new int[LINE];
int curPin = 0;
int turn = 1;
Random generator = new Random(); …Run Code Online (Sandbox Code Playgroud) 1)为什么我们使用DTO和DAO,何时使用它们.我正在开发一个GUIJava软件来处理插入,编辑,删除数据.但我很努力区分DTO/DAO和Model,View,Controller(MVC)结构?它们是否相似,最好在通过Java与数据库交互时使用GUI.
2)我真正好奇的一件事是view,Controller在一堂课中是否是一个好习惯.如果我们考虑一下Netbeans,你可以创建GUIFrame Class并JButton在框架上添加组件,双击该按钮会将你带到actionListener方法(Controller),该方法似乎在框架中,数据将显示给用户(View) .所以他们在同一个班级.这完全违背了这个概念吗?
这就是我所说的
在一个类中拥有视图和控制器的不良做法?
有人可以解释一下Django和模型视图控制器模式之间的差异吗?
从功能上来说,我们可以从这些差异中得到什么 - 例如,将Django与Ruby on Rails进行比较的方式有何不同?
如果我的控制器的URL被正确保护,我试图弄清楚如何进行单元测试.以防有人改变现状并意外删除安全设置.
我的控制器方法如下所示:
@RequestMapping("/api/v1/resource/test")
@Secured("ROLE_USER")
public @ResonseBody String test() {
return "test";
}
Run Code Online (Sandbox Code Playgroud)
我设置了一个WebTestEnvironment,如下所示:
import javax.annotation.Resource;
import javax.naming.NamingException;
import javax.sql.DataSource;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.web.FilterChainProxy;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration({
"file:src/main/webapp/WEB-INF/spring/security.xml",
"file:src/main/webapp/WEB-INF/spring/applicationContext.xml",
"file:src/main/webapp/WEB-INF/spring/servlet-context.xml" })
public class WebappTestEnvironment2 {
@Resource
private FilterChainProxy springSecurityFilterChain;
@Autowired
@Qualifier("databaseUserService")
protected UserDetailsService userDetailsService;
@Autowired
private WebApplicationContext wac;
@Autowired …Run Code Online (Sandbox Code Playgroud) java ×2
javascript ×2
swing ×2
.net ×1
angularjs ×1
attributes ×1
backbone.js ×1
css ×1
django ×1
forms ×1
frameworks ×1
javabeans ×1
jquery ×1
junit ×1
security ×1
spring ×1
testing ×1
winforms ×1